Skip to content

perf: string and vector hot paths (CLJW-PERF-STRINGS-COLLS) - #85

Merged
BuddhiLW merged 4 commits into
stagingfrom
swarm/perf-strings
Oct 22, 2026
Merged

BuddhiLW merged 4 commits into
stagingfrom
swarm/perf-strings

Conversation

@BuddhiLW

Copy link
Copy Markdown
Owner

Kanban 20261022150535-67056ef8. Step toward decision 20261022012219-31249feb (cljw faster than bb on every benchmark).

Changes (ledger O-070..O-077)

  • O-070 clojure.string/join: native walk over any seqable (was apply str + interpose)
  • O-071 upper/lower-case: byte-wise fold for all-ASCII input
  • O-072 split: one regex VM for the whole split, fromSlice result
  • O-073 subvec: native in-bounds integer fast path, unchanged coercing/throwing fallback
  • O-074 vector node copies write each slot once
  • O-075 str: stack buffer when every arg is a string, immediate int or nil
  • O-076 keyword intern: stack-key probe, so a hit allocates nothing
  • O-077 dorun/doall: native walk, a realized chunk at a time

Fallbacks keep the old general path, so semantics are unchanged. Spot-checked against clj/bb: join over vector/list/string/map/set with nil, char and keyword elements; split with empty pieces; ß upper-case; subvec nested, float-index, out-of-bounds and nil errors; str overflow past the buffer; keyword identity; dorun side-effect order over lazy/concat seqs.

bench/vs_bb in-proc ms (min of 3, ReleaseSafe; the box was shared with other builds)

cell before cljw/bb after cljw/bb
string_ops 3760 / 403 = 9.33x 943 / 415 = 2.27x (2nd run under heavier load: 979/325)
vector_assoc 1452 / 448 = 3.24x 1041 / 495 = 2.10x; A/B of the last commit alone: ~950 to ~800 ms
subvec probe 1.36 us vs bb 0.11 us (12x) O(1) native step; the subvec loop in vector_assoc takes 3 ms

Still slower than bb. What remains is mostly the per-call closure cost inside map/mapv (VM call path, not in scope here) and persistent map assoc.

Checks: check_core_surface, check_doc_coverage, check_placement_status (placement regenerated), check_epipe_head pass; zig build test VM + tree_walk pass in smoke.

clojure.string/join walks its coll natively (O-070); upper/lower-case
fold all-ASCII input byte-wise (O-071); split reuses one regex VM and
bulk-builds its vector (O-072); subvec answers the in-bounds int case in
one native step (O-073); vector node copies write each slot once (O-074).

bench/vs_bb in-proc vs bb: string_ops 9.33x -> 2.27x,
vector_assoc 3.24x -> 1.94x.

Smell-audited: 1: fast paths fall back to the unchanged general path on any other shape
str of string/int/nil args concatenates in a stack buffer (O-075);
keyword intern probes with a stack-built key so a hit allocates nothing
(O-076); dorun walks natively, a realized chunk at a time (O-077).

Micro, ReleaseSafe: (str "item-" i "-x") x500k 316 -> 144 ms,
(keyword "abc") x500k 235 -> 104 ms, doall over map 225 -> 135 ms.
vector_assoc in-proc A/B ~950 -> ~800 ms.

Smell-audited: 1: each fast path falls back to the unchanged general path
@BuddhiLW

Copy link
Copy Markdown
Owner Author

Smoke (test/run_all.sh --smoke with the string/regex e2e and clj suites) is re-running on 8d1abf5. zig_build_test_vm and tree_walk passed on the first run; that run's log was overwritten by another job sharing the /tmp name. Result: /tmp/perfstrings-smoke-8d1abf5d.log.

data/placement.yaml regenerated against the merged runtime (1462 vars).

Smell-audited: 0: generated index only
.dev/optimizations.md resolved as the union of both sides (O-070..O-077
here, O-090 from #87).

Smell-audited: 0: ledger union only
BuddhiLW added a commit that referenced this pull request Oct 22, 2026
.dev/optimizations.md and .dev/debt.yaml conflicted on every parallel PR
on 2026-10-22 (#85, #86 against #87), always as two sides appending rows.
git's union driver resolves exactly that; check_yaml and the ledger gates
still validate the result.

Smell-audited: 1: merge driver for a recurring mechanical conflict
@BuddhiLW
BuddhiLW merged commit 06abc57 into staging Oct 22, 2026
2 of 3 checks passed
BuddhiLW added a commit that referenced this pull request Oct 22, 2026
.dev/optimizations.md resolved as the union of both sides (this branch's
O-080/O-081 and #85's O-070..O-077); from now on .gitattributes merges it
by union.

Smell-audited: 0: ledger union only
@BuddhiLW
BuddhiLW deleted the swarm/perf-strings branch October 22, 2026 23:02
BuddhiLW added a commit that referenced this pull request Oct 22, 2026
data/placement.yaml regenerated against the merged runtime.

Smell-audited: 0: generated index only
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.

1 participant