6 ms·
"Programmers of elegant scripting languages desire similarly elegant looking code with flexible data structures even where no flexibility is in play. Some who k
by joe_the_user 14y ago
"Programmers of elegant scripting languages desire similarly elegant looking code with flexible data structures even where no flexibility is in play. Some who know better will understand that technical limitations make the difference between hashes and other types of named lookups essentially nil for many popular language runtimes."
OK, if no flexibility is in play in many usages of hashmaps, should not an intelligent interpreter/compiler be able to detect this and modify the use of the hashmap accordingly? Maybe even use a different lookup system in those cases? It seems like that would be ... elegant.
The reason VMs don't need to be slow is that you don't need to treat an eval call literally, you don't always need to create a full environment to parse a twenty character string, right? But if you can get around that, should you not be able to get around hash-map's problems? Am I missing something.
- cjh_ 14y agoThis question is partially address in the articles linked to at the start [1] I linked to the slide that begins to mention it, rather short though. The answer is that we can add heuristics, but that we should also be able to solve this somewhat on a language/library level rather than only at a vm level. [1] https://speakerdeck.com/alex/why-python-ruby-and-javascript-are-slow?slide=34 https://speakerdeck.com/alex/why-python-ruby-and-javascript-...
- joe_the_user 14y agoYeah, Perhaps if I saw/heard the talk I would get more out of it than "data-structure heuristics are the worst". It would be nice to know why they are the worst.
- makomk 14y agoPython already has a feature called __slots__ which replaces the dictionary normally used to store object attributes with fixed, well, slots.
- jes5199 14y agoDoesn't the V8 javascript engine do something like this? Where it builds C-structs instead of hashmaps if it can detect that your objects are being built in a consistent way
- maggit 14y agoYes. They call it "hidden classes": https://developers.google.com/v8/design#prop_access https://developers.google.com/v8/design#prop_access
- gngeal 14y agoSelf-93, the language that pioneered this approach for dynamic native compilation, celebrates it 20th birthday this year.
- gsnedders 14y agoSo does PyPy, but only for objects (and not for hashmaps, i.e., the dict object).
- Too 14y agoIIRC the Dictionary<TKey, TValue> in .NET does this. If you have less than 8 items in it a lookup is simply iterating over the keys like a plain array instead of keeping a hashmap.