Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using arrays and linear search for small hash maps. #22642

Open
DartBot opened this issue Mar 3, 2015 · 2 comments
Open

Consider using arrays and linear search for small hash maps. #22642

DartBot opened this issue Mar 3, 2015 · 2 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a library-core type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Mar 3, 2015

This issue was originally filed by @mdakin


Alex Tatumizer made some tests and reported better performance using arrays + linear serch for small maps: https://groups.google.com/a/dartlang.org/d/topic/misc/CjRvg2pyG3I/discussion

Idea is, for small hash maps, store keys, hashes for keys and values in separate arrays , and when doing lookups only do a linear search on key hashes. When same hash is found, check for key equality, if equals, return index, if not return null. During insertion it checks for (a very unlikely) hash collision and if there is one falls back to normal map implementation.

It is faster than currenct Compact hash map for lookups and insertions (https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/runtime/lib/compact_hash.dart) because of its simplicity and guarantee of no collisions (It does at most 1 equals check)

It is 1.4-2x faster than current map implementation for small sizes (<16) , performances are same around map size of 30 (On Intel I7). Cut off is probably lower on older CPU's. 16 would be a good number.

Alex's original code: https://gist.github.com/tatumizer/91a887e802594becaa8c

Same code with my small changes: https://gist.github.com/mdakin/db6e0b780ccd11ea0b8b
My Results: https://gist.github.com/mdakin/12d9ac332f2cf5abfa46

We believe performance gains justified having a simple array based implementation inside current hashmap because small hashmaps are very common.

@mraleph
Copy link
Member

mraleph commented Mar 3, 2015

cc @kodandersson.
Added Area-Library, Accepted labels.

@lrhn
Copy link
Member

lrhn commented Mar 11, 2015

Removed Type-Defect label.
Added Type-Enhancement label.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Mar 11, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-a library-core type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants