goldmansachs / gs-collections

GS Collections has been migrated to the Eclipse Foundation, re-branded as Eclipse Collections. https://www.eclipse.org/collections/
https://www.eclipse.org/collections/
1.81k stars 276 forks source link

Avoid double probe #34

Closed chrisc36 closed 6 years ago

chrisc36 commented 8 years ago

Another performance issue, I can look into patching this on the Eclipse Collections project as well.

For, primitive object maps, "ObjectHashMap" the "getIfAbsent" method calls the probe function twice, basically doubling the cost of a hash lookup. The problem are the lines:

        int index = this.probe(key);
        if (this.keys[this.probe(key)] == key)

the precomputed index value is recomputed from scratch on the second line!

itohro commented 8 years ago

Very good catch and please do submit a pull request to Eclipse Collections!

nikhilnanivadekar commented 6 years ago

@chrisc36 this has been fixed in Eclipse Collections via PR: https://github.com/eclipse/eclipse-collections/pull/401 It will be a part of Eclipse Collections 9.1.0 release.