perf: P9 - TakeOut/PutBack on the map #56
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
F10: the member that reaches a map entry. Waits until there are two back ends to answer to.
Source
Acceptance criteria
Dependencies
None known.
Moved from the planning lists of the docs; the design record stays the specification.
[loop:torbscript] intake: in scope (author orion, label loop), source PERFORMANCE.md round P9, not a duplicate. The record says it waits until there are two back ends to answer to; refine checks that against the current state (the VM exists) and measures in forge CI. next: refine, waiting (ready buffer full: #4, #163, #164, #223 are ready) until 2026-10-10T04:00:00Z
[loop:torbscript] claim refine by session:loop-torbscript-20261023 until 2026-10-23T04:31:18Z
[loop:torbscript] decided by the loop: P9 is unblocked and is cut to its core; the member rework follows as its own step.
compiler/src/backend/bytecode,compiler/src/vm; VM.md is "implemented", milestone 7). The same holds for #58 (P11) and #59 (P12), which carry the same "after the VM" gate; P9 does not depend on either.Instruction.TakeOut/PutBackwithRuntimeKind.Mapexist in the IR and nothing reaches them;torb_map_take_out/torb_map_put_backexist inruntime/map.cbut there is notorb_map_slot; the bytecode emitter rejects both instructions ("avarpath through a map");place.trblowers a map path as agetplus aset(two probes, value copied both ways);Map.update/getOrInsertinstd/collections/src/map.trbare written asget+set.benchmarks/map-count5.78x against the C reference, 50 048 allocations, the key hashed twice per word.getOrInsert/updaterework on top of it is the next step and is filed just in time once this one has landed (after a keyword duplicate search), not now.[loop:torbscript] refine: ready.
Goal. A read-modify-write and a write through
map[key]on a concrete map probe the table once: the pair ofget/set(and the take-out/put-back of two members) becomes oneTakeOutand onePutBackwithRuntimeKind.Map, on an interior pointer from a newtorb_map_slot, in both back ends (PERFORMANCE.md F10 / round P9, "the fix", first half).Acceptance criteria
runtime/map.cgainstorb_map_slot(map, key): a pointer to the value slot, valid until the next write to the table; a missing key is the insert/panic the currentMutableIndex.set/Index.atpair produces, with the same message.ir/elements.trbor a sibling, plusir/lower/place.trb) turns the round trip on a concrete map into onetakeOutand oneputBack;ir/verify.trbaccepts them. A new IR snapshot test shows onetakeOut/putBackwheremainshows twocallWitness.TakeOut/PutBackon a map (the tworeportsites inbackend/bytecode/emit.trbare gone, a kernel operation carries it).map[a][b].f = v, a value that is a counted type (copy on write aftermakeUnique), and a write inside the access that would rehash (rejected by exclusivity, test pins it).benchmarks/map-countrun in forge CI on the PR's base and head withbenchmarks/run.sh(same runner, RUNS=9, fastest of them). Passes if the ratio against C drops from the 5.78x baseline by at least 20% on the same runner, and allocations do not exceed 50 048. If the measured gain is below that, the PR documents the numbers and the loop decides then (keep, because the copy goes away, or drop); no owner question either way.skills/regenerated.Design record.
docs/PERFORMANCE.mdF10 and round P9 (section 5),docs/design/VM.mdfor the kernel operation. The "after the VM" condition is met (see above).Seed impact. No syntax change and no std name the compiler looks up by string. A new native-level entry (
torb_map_slotand a VM kernel operation) is involved, so the two-commit rule applies: commit 1perf(runtime): torb_map_slot and the map take-out in the VM(runtime + bytecode emitter + VM, nothing reaches it yet, tests at IR level), commit 2perf(ir): a map read-modify-write is one probe(pass, C emission, snapshot, benchmark, docs). The seed refresh itself is not part of this and stays with the owner.Out of scope (next step, just in time):
Map.getOrInsert/Map.updatewritten on top of the slot.Tokens for this refine run: roughly 60k (read-only repo check, no CI run needed before ready since the baseline is already recorded; CI measurement is the PR's criterion).
[loop:torbscript] claim implement by session:loop-torbscript-20261023 until 2026-10-23T08:41:20Z
ArrayList, the hash tables and the tries onBuffer(step 1 of #55) #413ArrayList, the hash tables and the tries onBuffer#55forover a flat list in PERFORMANCE.md (step 1 of #58) #415forover a concrete list is a counted loop #58Buffer.holdsClose(step 2 of #55, commit 1 of 2) #468Buffer.holdsClose(step 2 of #55, commit 1 of 2) #468forpass over a flat list (step 2 of #58) #470