Skip to content

perf: fused emit for no-split add and non-rebalancing remove - #4

Merged
tiensonqin merged 2 commits into
mainfrom
perf/add-insert-fast-path
Oct 10, 2026
Merged

tiensonqin merged 2 commits into
mainfrom
perf/add-insert-fast-path

Conversation

@tiensonqin

Copy link
Copy Markdown
Contributor

Summary

Two insert/remove-path optimizations that skip the generic chunking machinery when an add or remove does not need to split or rebalance. Serialized node bytes are unchanged — verified by byte-identical structure hashes across native, js_of_ocaml, and upstream cljs on the same seed data.

  • add (d4a8ca5): when a leaf or branch has room for the new element, emit the updated node directly instead of running the full insert pipeline. In datascript-ocaml's add-1 bench this shaved ~5% off transaction time (PSS insert is the dominant transact cost at ~2.1µs × 3 indexes).
  • remove (b4c97e3): the symmetric fast path for branch child replacement that cannot trigger a rebalance — emit the replacement node rather than rebuilding through the generic chunking chain.

Both paths fall through to the existing generic implementation whenever a split or rebalance is actually required, so behavior on overflow is unchanged.

Link to Devin session: https://app.devin.ai/sessions/a699c982a95844238c1dcd1ff6cc8d5d
Open in Devin Desktop: https://app.devin.ai/desktop/session/a699c982a95844238c1dcd1ff6cc8d5d?variant=devin
Requested by: @tiensonqin

When a leaf or branch does not split after an insert, emit the updated
node directly instead of going through the generic chunking pipelines
(add_leaf_refs / tree_*_refs_of_arrays / branch_replace_one). This
mirrors the direct emission remove already uses for leaves and saves a
few intermediate allocations and list traversals per add. Tree shape and
node contents are unchanged.
When a removed child does not underflow, the branch keeps its shape —
replace the child slot in place and emit the branch directly instead of
routing through branch_replace_one's generic ref-array chunking.
@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@tiensonqin
tiensonqin merged commit 634fc5e into main Oct 10, 2026
2 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.

1 participant