contain-rs / linked-hash-map

A HashMap wrapper that holds key-value pairs in insertion order
https://contain-rs.github.io/linked-hash-map/linked_hash_map/
Apache License 2.0
169 stars 60 forks source link

Avoid allocations on creation & recycle nodes to avoid allocations #25

Closed arthurprs closed 9 years ago

arthurprs commented 9 years ago

The first commit is obvious.

As for the second, it shaves a good 25% in a remove-insert cycle (as seen in the included benchmark). The memory usage patterns are consistent with a plain HashMap and it's possible to clear the free list by calling shrink_to_fit.

test tests::not_recycled_cycling ... bench:     218,208 ns/iter (+/- 14,423)
test tests::recycled_cycling     ... bench:     160,986 ns/iter (+/- 9,258)
FlashCat commented 9 years ago

r? @huonw

(I've picked a reviewer for you, use r? to override)

huonw commented 9 years ago

r? @Gankro

Gankra commented 9 years ago

This is super cool!

I'm kinda blurry-brained right now. Feel free to reping me if I don't review this in the next day or two.

apasel422 commented 9 years ago

If/when this is merged, it'd be good to push a new version to crates.io.

Gankra commented 9 years ago

I just published 0.0.5. @arthurprs feel free to toss a "0.0.6 release" commit in here if you want.

arthurprs commented 9 years ago

@Gankro, rebased and added the 0.0.6 release commit

arthurprs commented 9 years ago

ping @Gankro (as requested)

Gankra commented 9 years ago

r=me with nits

arthurprs commented 9 years ago

@Gankro Thank you for the review. I rebased the commits to account for your suggestions.

Gankra commented 9 years ago

Thanks!