Hacker News new | past | comments | ask | show | jobs | submit login

You're off base. There is a distinction: objects are not hash tables. JS doesn't have hash tables, not natively. Object behavior might be implemented as a hash behind the scenes, or it might not— V8, for example, does it with hidden C++ classes in a way I don't totally get that's described here: http://code.google.com/intl/sv/apis/v8/design.html#prop_acce... . This has the (purported) benefit of being actually faster than hash lookups. Yes, really.

If you desire some piece of behavior you're used to from hash tables in other languages, you can of course implement that yourself on top of the JS object. Or you could learn to live with abstractions that don't leak.




V8 does not use "hidden C++ classes." It specializes a memory layout for each object layout and uses tracing to optimize property access into direct offset reads/writes.


I'm willing to believe you, but I didn't make that up, I was just cribbing from the link: To reduce the time required to access JavaScript properties, V8 does not use dynamic lookup to access properties. Instead, V8 dynamically creates hidden classes behind the scenes.

I gather a "hidden class" is not an idiom of C++ as I'd assumed, rather something V8 people made up, but that's what they call it.


the technique is called "inline caching". "tracing" is a completely different approach to JITs.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: