문제

I'm doing a data-intensive project in Javascript, where there are thousands of objects with short strings as "IDs" that need to be looked up efficiently by ID. My (possibly naive) approach was to create an object with a property for each object, keyed by the ID.

How do different browsers/JS engines implement key lookup in very large objects like this? I know that V8 is highly optimized for objects with a small number of properties, but what happens if there are thousands of properties that are constantly added and deleted? Are objects backed by hash tables or tries in the different browsers? Either way, I'd imagine there's a benefit to using shorter keys, but does anyone have insight into whether that's a large benefit? And are there any browsers that are so bad at key lookup (i.e. do any use sequential search?) that it would be more performant to roll my own data structure?

도움이 되었습니까?

해결책

How very co-incidental. There was a question a few days ago about this. The OP generated some benchmarks to test and posted them only a few hours ago. I suggest you check it out: JavaScript Objects as Hashes? Is the complexity greater than O(1)?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top