usethesource / capsule

The Capsule Hash Trie Collections Library
BSD 2-Clause "Simplified" License
404 stars 27 forks source link

Reduce allocations empty of EnumSet inside MultimapResultImpl #20

Closed DavyLandman closed 5 years ago

DavyLandman commented 5 years ago

After profiling a phase of the rascal bootstrap, I saw that there were 20GB of allocation of the EnumSet.noneOf() empty EnumSets. So I change MultimapResultImpl to keep around a single instance of the set to avoid the allocations of it. All test still run correctly, so thats a postive sign.

The only global effect is that I've changed the interface to Set, such that I can put the shared EnumSet unside an ImmutableSet wrapper.

note that the MultimapResultImpl is also allocated a lot (10GB), but since it's an mutable object, it's harder to share. Maybe if we made it immutable, it would be easier to avoid all the allocations of unchanged().

btw, is master the right branch to release this from?

DavyLandman commented 5 years ago

okay, after writing this PR, I realized there is a different way to achieve it, without the extra wrapped set. I think this is a better approach now.

DavyLandman commented 5 years ago

note that the MultimapResultImpl is also allocated a lot (10GB), but since it's an mutable object, it's harder to share. Maybe if we made it immutable, it would be easier to avoid all the allocations of unchanged().

In the last commit I replaced the EnumSet with a int that uses the bits to flag if an enum is set. So no more extra allocations for the EnumSets.

DavyLandman commented 5 years ago

Thanks!