You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: reduce stream and builtin dispatch allocations - #2969
Builtin plan lookup and execution now call the underlying trait object directly, removing the boxed forwarding future at each boundary. Both future construction and polling remain inside the panic boundary.
Appending text and individual bytes to shell streams writes directly into the existing buffers. Joining streams skips decoding checks when the join cannot complete a split UTF-8 scalar. Scripts continue to use ordinary Bash syntax; no shared cache is introduced.
Why
Small shell commands repeatedly allocate forwarding futures and temporary byte/text buffers. Removing these intermediates reduces per-command work while preserving builtin hooks, execution plans and byte-stream behavior.
Before / After
Final combined-patch release runs compared 100-command scripts over five alternating rounds of 100 measured executions per build after local validation builds finished. Values are medians of round medians. Every result asserted exact stdout, stderr, and status; all 5,000 measured executions passed.
Workload
Before
After
Time reduction
Allocation calls
Empty builtin loop
0.527 ms
0.490 ms
7.1%
4,900 to 4,700
Output loop
0.658 ms
0.629 ms
4.4%
6,725 to 6,223
Substitution loop
1.897 ms
1.795 ms
5.4%
19,385 to 18,583
Pipeline loop
2.942 ms
2.859 ms
2.8%
33,932 to 33,230
Existing 100-warehouse fan-out
9.114 ms
9.036 ms
0.9%
99,958 to 99,539
Timings include allocation-counter instrumentation. The fan-out improvement was below 1%. The 100-call empty-builtin script also requests 23,112 fewer allocated bytes; requested bytes are cumulative allocation sizes, not peak memory.
The broader benchmark completed all 96 cases with zero errors and 100% output matching against GNU Bash 5.2. Its generated result artifacts are included. Local just pre-pr, just test, and cargo clippy --locked --all-targets --all-features -- -D warnings pass. CLI substitution and pipeline output matches Bash byte for byte, including UTF-8, NUL and invalid bytes.
The required dependency audit found RUSTSEC-2026-0592 in the existing url 2.5.8 dependency. All five affected Rust lockfiles now resolve the patched 2.5.9 release and its required form_urlencoded 1.2.3 dependency; the reviewed delta audits are recorded. The scoped URL update also selected cssparser-macros' compatible, already-present syn 2 edge; this resolver change was reviewed and confirmed on its review thread.
Risk
Stream appends must keep the cached lossy text equal to decoding the canonical byte buffer. Randomized byte/text appends and deterministic UTF-8 split cases cover this invariant.
Custom builtin methods may panic while constructing a future. The new manually implemented builtin regression fails before the containment fix and passes after it, covering plan lookup and execution with redirected diagnostics.
Review summary — perf: reduce stream and builtin dispatch allocations (merged as 6344cde)
Verdict: No blockers. The final push reworked the dispatch change to close a panic-containment gap (see below) with a targeted regression test, and added benchmark evidence. No new inline findings. Note: the PR is merged; this is a post-merge review, so no review action was submitted.
What changed since the last review (+2 commits):
Containment fix (the important one): the previous revision called AssertUnwindSafe(builtin.as_ref().execute(ctx)), which constructs the builtin's future outsidecatch_unwind. For #[async_trait] builtins that is harmless (bodies run on poll), but a manually implemented Builtin (plain fn returning a boxed future — permitted by the desugared trait signature) executes user code during the call itself, so a construction-time panic would have escaped TM-INT-001's boundary. I missed this in my prior pass — the author's new PanicWhileCreatingFuture test nails exactly that case. The merged code wraps both construction and polling inside the boundary (AssertUnwindSafe(async { builtin.as_ref().execute(ctx).await }), same for execution_plan), which restores containment with no extra box (the async block is unboxed; the outer Box::pin is unchanged). The new test covers both boundaries and asserts the normal failed unexpectedly / exit-1 path with redirections applied. Verified the execute-site Err(_panic) arm flows into the standard redirect/diagnostic/hook pipeline like any other error.
crates/bashkit-bench/results/bench-*.json/.md: new benchmark report (96 cases, bashkit vs bash, machine-generated). Both JSON files parse; contents are data, not reviewed line-by-line.
site/src/data/performance-timeline.json: timeline updated with the new point (valid JSON). Data only.
Earlier P2 (lockfile-unexplained-syn-downgrade, cssparser-macrossyn 3.0.10→2.0.119) shipped unaddressed — flagging here for the record since inline review is closed. Harmless either way (build-time dep, resolver-consistent).
Standing conclusions from prior passes (all still valid at merge head): stream append/append_text/push_byte fast paths preserve the bytes-canonical/lossy-text invariant; url 2.5.9 + form_urlencoded 1.2.3 bumps match cargo-vet audit entries and the url = "2" requirement; knowledge updates (architecture.md, builtins.md) match the shipped behavior.
Could not review: full diff inspected via hunk headers + head files; bench/timeline numbers and test/CI results taken on trust (no builds in this reviewer).
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
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 changed
Builtin plan lookup and execution now call the underlying trait object directly, removing the boxed forwarding future at each boundary. Both future construction and polling remain inside the panic boundary.
Appending text and individual bytes to shell streams writes directly into the existing buffers. Joining streams skips decoding checks when the join cannot complete a split UTF-8 scalar. Scripts continue to use ordinary Bash syntax; no shared cache is introduced.
Why
Small shell commands repeatedly allocate forwarding futures and temporary byte/text buffers. Removing these intermediates reduces per-command work while preserving builtin hooks, execution plans and byte-stream behavior.
Before / After
Final combined-patch release runs compared 100-command scripts over five alternating rounds of 100 measured executions per build after local validation builds finished. Values are medians of round medians. Every result asserted exact stdout, stderr, and status; all 5,000 measured executions passed.
Timings include allocation-counter instrumentation. The fan-out improvement was below 1%. The 100-call empty-builtin script also requests 23,112 fewer allocated bytes; requested bytes are cumulative allocation sizes, not peak memory.
The broader benchmark completed all 96 cases with zero errors and 100% output matching against GNU Bash 5.2. Its generated result artifacts are included. Local
just pre-pr,just test, andcargo clippy --locked --all-targets --all-features -- -D warningspass. CLI substitution and pipeline output matches Bash byte for byte, including UTF-8, NUL and invalid bytes.The required dependency audit found RUSTSEC-2026-0592 in the existing
url2.5.8 dependency. All five affected Rust lockfiles now resolve the patched 2.5.9 release and its required form_urlencoded 1.2.3 dependency; the reviewed delta audits are recorded. The scoped URL update also selected cssparser-macros' compatible, already-present syn 2 edge; this resolver change was reviewed and confirmed on its review thread.Risk
Checklist