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

proposal: arena: add MakeMap #56230

Closed
dsnet opened this issue Oct 14, 2022 · 4 comments
Closed

proposal: arena: add MakeMap #56230

dsnet opened this issue Oct 14, 2022 · 4 comments

Comments

@dsnet
Copy link
Member

dsnet commented Oct 14, 2022

I noticed that making of Go maps was missing from the original proposal in #51317. The proposal says:

Another open issue is whether arenas can be used for allocating the elements of a map. This is
possible, but it is not clear what a good API would be. Also, there might be unusual cases if the arena used for the main map object is different from the arena used to allocate new elements of the map.

Perhaps I'm missing something, but couldn't we construct a Go map with an arena registered with it such that all allocations needed by the map are performed out of the arena? Thus, we're not directly allocating the elements of a map, but rather the entire map and (indirectly any map elements henceforth).

Something like:

// MakeMap creates a new map[K]V with the provided capacity.
// The map[K]V must not be used after the arena is freed.
// Accessing the underlying storage of the map after free may result in a fault,
// but this fault is also not guaranteed.
func MakeMap[K comparable, V any](a *Arena, cap int) map[K]V { ... }

\cc @danscales

@dsnet dsnet added the Proposal label Oct 14, 2022
@gopherbot gopherbot added this to the Proposal milestone Oct 14, 2022
@bcmills
Copy link
Contributor

bcmills commented Oct 14, 2022

CC @mknyszek

@mknyszek
Copy link
Contributor

mknyszek commented Oct 14, 2022

I think this is the right way to do it, but I don't plan on implementing it any time soon. The map basically needs to carry an allocator around internally for whatever it might do (already a bit complex because we're so careful about how big the internal data structures are and how they fit into size classes), and then cloning the map out of the arena will be a bit complex too.

There was recently some discussion about actually supporting multiple map implementations under the hood for various use cases (I think this came up, possibly, in the context of SwissTables) in which case an interesting idea would be to have a map implementation specifically tailored to being created in an arena.

@mknyszek
Copy link
Contributor

By implementing it, I mean as part of the GOEXPERIMENT.

@mknyszek
Copy link
Contributor

I suppose in the same token that @rsc closed #56234, this should also probably be closed as a duplicate of #51317. I assume you meant that this issue and that one should go back into the original proposal, so I'll go ahead and reference this in #51317.

@mknyszek mknyszek closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2022
@golang golang locked and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants