Closed Marsup closed 6 years ago
I'm suggesting also having in the same Map the opposite, that is <ref, [objs]>
, this seems more efficient than iterating through all possibilities.
The map + set implementation does not iterate. Both lookups are O(1)
complexity.
Anyway, it will be quite uncommon to encounter objects that have these kind of references, thus we should optimize for that case. For instance the entire hapi test suite has 0 of such compares.
I meant iterating on tuples like you mentioned, I think it's preferable to keep it in the Map/Set.
Hmm, some benchmarking confirms that you are somewhat right. While the lookups are indeed faster with the map solution, the set()
is slower than the push()
.
In reality, it depends on the amount of objects that are seen during the comparison.
For 1 - 50 seens, map is slightly slower at up to ~30% performance loss. At 1000 seens, it is ~5x faster. At 10000 seens, it is ~50x faster.
Note the compared iterating pair implementations is highly optimized, using a custom class instead of a plain array for the pair.
All in all, I prefer the optimized map implementation.
So keeping it like that ? Do you think it's worth adding the reverse lookup ?
I assume this is no longer needed.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
Fixes #236.
Ideally we should probably compare those as couples, I could make a reverse lookup but I'm not sure it's necessary.