Problem
Strong Map/Set storage keeps an append-only ordered elements list and marks deletions as tombstones.
Map.prototype.size,Set.prototype.size, native size queries, and set operations rescan the entire historical list, so a nominally constant-time property becomes O(total historical insertions).- Delete/reinsert churn retains entry cells, tombstones, and index-position side storage indefinitely;
clear()shrinks logical length but ordinary deletion never compacts. - Collection iterators store a physical
__ilist position, preventing safe in-place compaction while an iterator remains live. Mapentry iteration currently yields the internal[key, value]storage pair instead of a fresh iterator-result pair. User mutation can therefore alter Map storage outsideMap.setand bypass index/write-barrier invariants.
This is a correctness, bounded-memory, and adversarial-complexity boundary.
Required outcome
- Maintain the strong collection live-entry count under the existing elements lock so every size query is O(1), including no-GIL readers racing mutation.
- Return fresh arrays from Map
entries()/ default iteration; user mutation must never mutate internal Map data. - Give iteration a stable logical insertion cursor independent of physical storage positions. Preserve deletion, clear, re-add, mutation-during-iteration, forEach, and multiple concurrent iterator semantics exactly.
- Compact tombstones in place at a documented bounded threshold, rebuilding position-only hash chains without managed pointers or allocation once compaction begins.
- Bound retained ordered/index/cursor storage under repeated insert/delete and clear cycles; teardown must release every side structure.
- Keep
SameValueZero, insertion order, subclass hooks, structured clone, moving GC, OOM failure atomicity, and no-GIL synchronization intact. - Add deterministic work/count/capacity growth witnesses, iterator mutation tests, moving-GC, structured-clone, OOM/fault, no-GIL, TSan, and full Map/Set test262 coverage.
- Publish exact-parent representative collections timing and retained-memory evidence before completion.
Relationships
Part of #475, #480, and #493. Follows the collision-safe identity index in #513 and contributes to #460.