4 ms·
Isn't there some kind of static analysis possible for such cases?
by amelius 8y ago
Isn't there some kind of static analysis possible for such cases?
- saagarjha 8y agoIf you could perform static analysis on these cases, why couldn’t the JIT just do so itself and not have any issues?
- amelius 8y agoWell, I suppose a JIT has tighter time constraints.
- arghwhat 8y agoJavaScript is too dynamic for such analysis. JavaScript at its core is not a very well designed language, and it's a bloody miracle that a JIT can make it usable. If you're designing a new language, don't make everything (even arrays!) a hashmap.
- j-pb 8y ago[1]In clojure the array type is basically a hashmap to enable high perf/low memory immutability. So I would say "Yes[1]" ^^
- arghwhat 8y agoI would certainly say "no" to having your basic array type be a hashmap as a hashmap is several orders of magnitude slower than an array for all operations on small arrays and for access for all sizes, although there is nothing wrong with also having hashmap and linked list collections if you need O(1) inserts. However, what I was referring to is much worse than that: JavaScript arrays are defined as a normal hashmap with string keys with hooks on assignment to parse the key as a uint32 and update the length property if the value is larger than the current one, and on length assignment iterate over all keys and delete those that successfully parse as a uint32 and has a numeric value larger than the one assigned to length.
- breatheoften 8y agoWow that’s depressing ...
- james-mcelwain 8y agoI thought dense arrays used linear storage and only fell back to a hashmap when they got sufficiently hole-y.
- Sawamara 8y agoYou say all this as if JS's jit engines (V8, chakra, spidermokey, etc) did not destroy "better designed" languages when it comes to speed and efficiency. The only dynamic language that does not pale beyond what is achieved with V8 is LuaJIT.
- ummonk 8y agoHow many "better designed" dynamic languages are there even out there? Julia is one such language and is substantially faster than V8, at least for idiomatic code. The problem is that most dynamic languages (like JS) are never designed with speed and efficiency in mind. JS just happens to be the fastest of that bunch (other than Lua) because browser makers have invested substantial effort into making it fast - far more than anyone has put into other dynamic languages.
- Sawamara 8y agoUsual suspects that many people who hate JS seem to champion are are python, lua, ruby. I love Lua personally, but it has its own traps too. Never could get into Python too much, the indentation syntax is killing me :P
- arghwhat 8y agoI hate JS with a passion (I worked with it professionally for years, and wrote crypto and compression algorithms, as well as an entire web browser sandbox), but my refuge is in static languages. I no longer see dynamic languages useful for more than bash-like scripting where correctness is uninteresting. :/
- deleted 8y ago[deleted]
- batmansmk 8y agoHmm, looking at the source code, you are partially correct. https://github.com/v8/v8/tree/master/src/objects https://github.com/v8/v8/tree/master/src/objects I can see at least 10 types which are not hash maps. Including all the flavors of Typed Arrays.
- squeaky-clean 8y agoThat's just how it optimizes their usage under-the-hood, but as far as JS is concerned they are all hash maps. For example, try this: var foo = [1,2,3]; // or `foo = new Array(1,2,3)` also works foo['bar'] = 'test'; console.log(foo); and you get: 0:1 1:2 2:3 bar:"test"
- arghwhat 8y agoAh yes, I had forgotten about Typed Arrays, which is a terrible name for what is in fact a buffer view. The entire arraybuffer/typedarray system was a later (≥IE10 if I am not mistaken?) hack added to make up for the fact that Array and Number are super inefficient for data processing. But regardless of them being a bandaid, you are correct that it is an exception. ArrayBuffer and all its views count 10 types in total, so were they the only exception? If so, I believe my point still stands.