Skip to content

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
shruti2522:refactor-wm
Mar 16, 2026
Merged

weak_map: replace entries in one lookup and research ephemron vs key/value pair for insert#50
nekevss merged 3 commits intoboa-dev:mainfrom
shruti2522:refactor-wm

Conversation

@shruti2522
Copy link
Contributor

Replaced the two step remove+insert update path with a single find_entry lookup + in place swap (mem::replace) in both mark_sweep and mark_sweep_arena2. Added function replace_or_insert to weak map internals

key/value pair vs. ephemeron:

I have looked into this thoroughly whether WeakMap::insert should take a prebuilt Ephemeron instead of (key,value), and here's what I have found.

I think key/value pair is the better approach. Taking an Ephemeron in 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 reclamation

WIP: this includes changes from Hashmap -> HashTable too since the changes here needed it, will be ready for review once that PR lands

@shruti2522 shruti2522 changed the title refactor(weak_map): replace entries in one lookup and research ephemron vs key/value pair for insert weak_map: replace entries in one lookup and research ephemron vs key/value pair for insert Mar 12, 2026

### `WeakMap<K, V>`

It's a `HashMap<usize, ArenaPointer<Ephemeron<K, V>>>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do that

@shruti2522 shruti2522 marked this pull request as ready for review March 15, 2026 04:15
@shruti2522
Copy link
Contributor Author

Added a new note explaining the changes made here and conclusion on key/pair vs. ephemeron. Ready for review now


fn insert_ptr(
// replace an existing entry in one lookup, invalidating the old ephemeron
fn replace_or_insert(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move forward with this! Thanks :)

@nekevss nekevss merged commit cc93e03 into boa-dev:main Mar 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants