Repository navigation
perf(transduce): native map, filter, remove and take transducer stages (O-111) - #133
Merged
Merged
Conversation
… comp WORK IN PROGRESS, not for merge. Preserved from ling cljw-transduce-fused (gpt-6.1) when its session ended before it committed. Native reducing-function objects for (map f), (filter pred), (remove pred), (take n) and their comp, with a native suite test/clj/suites/native_transducer_test.clj. Same-window interleaved measurements (in-process ms, instructions:u): - transduce: 3224 -> 1120 ms (bb 361); 28.82 G -> 11.21 G instructions. - legacy_transduce: 228 -> 138 ms; into_transient_checks 112 -> 87 ms. - reduce_map: 4088 -> 4304 ms in window 2 (no gain; noise-level). - lazy_chain, into_collections, vector_assoc, gc_large_heap within noise. Open before a PR: the GC torture run failed once with "swap!: expected atom, got ref" (torture97-tests exit 1; the retry exited 0). Find whether a native stage leaks a ref where an atom is expected under GC pressure, then rerun zig build test -Dwasm, all native suites and the torture smoke. Smell-audited: 1: WIP preserved with its open torture failure stated, not proposed for merge.
Verifies the native map, filter, remove and take transducer stages (O-111) against origin/staging 6c91f00 and records the samples. - bench/vs_bb/history.yaml: two interleaved best-of-5 rounds per side, ReleaseSafe -Dwasm, host load 38-67. Rows for 6c91f00 are the baseline binary; rows for f8faf0e are this branch. - Pinned (taskset -c 2, cpu_core instructions:u, 5 samples per side, interleaved): transduce 28.820G -> 11.208G (-61.1%), 10351 -> 4345 ms. No other workload moved by more than +0.7% in instructions. - .dev/optimizations.md: O-111 sat after a blank line, outside the table; it now continues the table. The GC torture flake the WIP commit recorded did not reproduce: six consecutive phase16_gc_torture runs and the smoke gate's run passed.
Keeps both sides. CHANGELOG.md: the native transducer stage entry and the GC allocation record entry both stay under [Unreleased] / Changed. .dev/optimizations.md: O-111 and O-092 both continue the table. Smell-audited: 0: merge only; no source line changed beyond the two sides.
Keeps both sides of invokeCallable: native transducer closures (O-111) dispatch through native_call first, then a fixed-arity .fn_val takes #132's resolved path (O-064). resolveFixedArity now returns null for a native closure. #132's reduce range and vector arms call it directly; a native map stage carries a variadic arity stub with no body, which the resolved binder would otherwise run instead of native_call. Smell-audited: 1: two-line guard plus conflict resolution, both behaviours kept.
BuddhiLW
marked this pull request as ready for review
December 1, 2026 13:39
bash scripts/gen_placement.sh after the O-111 stages. The only change is the four new Zig builtins cljw.internal/__map-xform, __filter-xform, __remove-xform and __take-xform (total 1472 -> 1476, zig 438 -> 442). check_placement_status, check_core_surface, check_doc_coverage and check_capability_claims pass locally.
BuddhiLW
added a commit
that referenced
this pull request
Dec 1, 2026
…zig-0.17.1 #133 was written for Zig 0.16. Ported here: transducer.zig's @intFromEnum / @enumFromInt become @backingInt / @fromBackingInt, and the two `Kind` decodes of an i64 capture take @intcast, since @fromBackingInt wants the exact backing integer. data/placement.yaml takes staging's (gen_placement.sh shows no drift under 0.17.1). native_transducer_test: 14 tests, 158 assertions, 0 failures on vm. Smell-audited: 1: forward merge plus the mechanical 0.17 port of the merged code
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.
What
Native reducing functions for the
map,filter,removeandtaketransducer stages (O-111, card CLJW-PERF-REDUCE-PATH).(map f)and the others now return nativeFunctionclosures that carrynative_call. A stage calls userf/predthroughinvokeCallable. It hands the element straight to the downstream rf, with novm.evalframe per stage per element.comp, user transducers, init/completion arities,reducedand the lazy collection arities keep their current behaviour.Commits:
f8faf0e7the implementation (preserved WIP from the ling session; its subject still says wip)bfffb4f7measurements, history rows, and an.dev/optimizations.mdtable fixVerification (against origin/staging 6c91f00)
zig build -Dwasm -Doptimize=ReleaseSafe: builds.bash test/run_all.sh --smoke e2e_phase16_gc_torture: green, 17/17 steps, includingzig_build_test_vm,zig_build_test_tree_walk(the dual-backend diff oracle) andtest_clj_suites(171 suites, 1000 tests, 5393 assertions).test/clj/suites/native_transducer_test.clj(14 tests, 158 assertions) passes on the JVM oracle (Clojure 1.12), on the VM binary and on a tree_walk binary. It covers early termination throughreduced, per-rftakestate, nested and reentranttake, completion arity,compordering, mixed user transducers, multi-inputmap, lazyapplytails, exceptions and forced GC inside callbacks.partition-all,dedupe,take-while,mapcat,eductionover(range), nestedtake,(take 0)and multi-collsequence.suites.gc-heap-return-test(committed-heap bounds). The baseline 6c91f00 tree_walk binary fails the same 2 assertions, so they come from the conservative stack scan and predate this branch.phase16_gc_torturefailed once withswap!: expected atom, got ref. That did not reproduce: 6 consecutive standalone runs plus the smoke gate's own run all passed.Measurements
Pinned A/B:
taskset -c 2,cpu_core/instructions/u, 5 interleaved samples per side, ReleaseSafe -Dwasm. Min instructions, with min in-process ms in brackets (the host was shared and loaded, so ms is noisy):No workload regresses by more than +0.7% in instructions.
reduce_mapuses the lazy multi-collmap, which these stages do not cover (see the card).bench/vs_bb/run.sh -n 5 --perf --no-jvm, two interleaved rounds per side (load 38 to 67). The four rows are appended tobench/vs_bb/history.yaml: transduce in-process best 3016 ms -> 1359 ms, cljw/bb 6.16 -> 2.84. Unpinnedinstructions:uthere mixes P-core and E-core counts and is not comparable across rows, which is why the pinned table above is the one to read.Merged with staging (#130 and #132)
9cc4eb87merges perf(gc): compact allocation records to reduce churn metadata #130 (gc-churn-2). Only CHANGELOG.md conflicted; both entries are kept under[Unreleased], and the O-111 and O-092 rows both stay in the optimizations table.6188344amerges perf(vm): flatten variadic calls at exact arity, resolve reduce callees once #132 (reduce-vm-step).invokeCallableconflicted: it now triesnative_callfirst, then perf(vm): flatten variadic calls at exact arity, resolve reduce callees once #132'sresolveFixedAritypath.resolveFixedArityalso returns null for a native closure. Without that guard, perf(vm): flatten variadic calls at exact arity, resolve reduce callees once #132'sreducerange and vector arms would hand a nativemapstage (a variadic arity stub with no body) to the resolved binder instead ofnative_call.After the merges (final sha 6188344 against staging b8a57ec)
bash test/run_all.sh --smoke e2e_phase16_gc_torture: green, 17/17 steps.native_transducer_test(14 tests, 158 assertions): passes on VM and tree_walk.taskset -c 2,cpu_core/instructions/u, 5 interleaved samples per side, min):The optimisations compose. #132 already took transduce from 28.82 G to 27.46 G, and the native stages take it to 11.09 G. reduce_map stays on #132's level, as expected, because its lazy multi-coll
maphas no transducer stage.