weak_map: replace entries in one lookup and research ephemron vs key/value pair for insert#50
Merged
nekevss merged 3 commits intoboa-dev:mainfrom Mar 16, 2026
Merged
Conversation
nekevss
reviewed
Mar 13, 2026
|
|
||
| ### `WeakMap<K, V>` | ||
|
|
||
| It's a `HashMap<usize, ArenaPointer<Ephemeron<K, V>>>`, |
Member
There was a problem hiding this comment.
nit: early feedback, but let's try to keep the notes as a time capsule. Create a new note and link to this one as a revision
Contributor
Author
There was a problem hiding this comment.
Sure, will do that
…/value pair approach for insert
Contributor
Author
|
Added a new note explaining the changes made here and conclusion on key/pair vs. ephemeron. Ready for review now |
nekevss
requested changes
Mar 16, 2026
|
|
||
| fn insert_ptr( | ||
| // replace an existing entry in one lookup, invalidating the old ephemeron | ||
| fn replace_or_insert( |
Member
There was a problem hiding this comment.
suggestion: let's make this insert, and return an Option.
This API is pretty standard for various other Rust map types, and we should adhere to it where possible.
…/value pair approach for insert
nekevss
approved these changes
Mar 16, 2026
Member
nekevss
left a comment
There was a problem hiding this comment.
Let's move forward with this! Thanks :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaced the two step remove+insert update path with a single
find_entrylookup + in place swap (mem::replace) in both mark_sweep and mark_sweep_arena2. Added functionreplace_or_insertto weak map internalskey/value pair vs. ephemeron:
I have looked into this thoroughly whether
WeakMap::insertshould take a prebuiltEphemeroninstead of (key,value), and here's what I have found.I think key/value pair is the better approach. Taking an
Ephemeronin insert would leak GC internals into the API, also it would make callers responsible to perform any collector specific allocation and queue registration which is wrong since the collector must own these to preserve invariants around sweeping and reclamationWIP: this includes changes from Hashmap -> HashTable too since the changes here needed it, will be ready for review once that PR lands