-
Notifications
You must be signed in to change notification settings - Fork 712
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
Remove LatestMap, to reduce memory allocation #2351
Conversation
aa6c2f4
to
ba757e6
Compare
Structs like StringLatestMap now use ps.Map directly, which saves a memory allocation for LatestEntry.Value to point to. The values in the ps.Map are now pointers, which saves a memory allocation indirecting a value type to an interface{}
ba757e6
to
9ca02f5
Compare
Some stats (run on a slightly different commit): Running the following test:
where On master, commit d64d66e:
With this PR, commit de97a72:
That's about a 15% speed-up, fastest to fastest. |
9ca02f5
to
ee657ba
Compare
ee657ba
to
de97a72
Compare
Did you find generate_latest_map useful? |
(i.e. we don't really need to maintain it, so I hope it was helpful and you didn't update it because it was there) |
Yes, it's easier to edit the code once and generate twice, than to edit it twice. |
Previously, classes like
StringLatestMap
were implemented as a shim overLatestMap
.This meant that the memory allocations were:
[
ps.Map
leaf] -> [interface{}
indirection] ->LatestEntry
-> [interface{}
indirection] -> [string contents]Removing
LatestMap
and storing the entry via pointer rather than value gives us instead:[
ps.Map
leaf] ->stringLatestEntry
-> [string contents]Also the
LatestEntry
was copied one more time on entry into the map. Thus this PR removes 50% of the memory allocations needed to create this particular structure, per entry.(not counting the allocation for the map key)