Repository navigation
perf(assign): reduce scalar allocations with measured Linux evidence - #620
Merged
Merged
Conversation
GNU ownership: variables.c:3054 bind_variable_internal and variables.c:3203 var_setvalue replace the scalar cell while preserving attributes; subst.c:3576 do_assignment_internal traces the computed RHS only when echo_command_at_execute is enabled. Linux verification: 583 lib tests, scalar-assignment CLI and xtrace CLI pass. Add fixed scalar/prefix workloads and an output-validated interleaved benchmark runner. Related to #609; does not close it or claim its GNU performance target is met.
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.
Scalar assignment: measured partial follow-up for #609
Scope and GNU ownership
Baseline:
334afab2. Candidate code:6752598ef8231c2c569eed3b51095ae0d3203d2b.GNU
variables.c:3054 bind_variable_internalreplaces the value of an existingscalar cell without changing its attributes. Rubash now reuses the existing
typed/mirror String capacities and mirror key instead of allocating replacement
copies. This does not collapse the two stores or bypass attribute checks.
GNU
subst.c:3576 do_assignment_internalcallsxtrace_print_assignmentonlywhen
echo_command_at_executeis enabled. Both permanent and temporary applypaths now populate the trace-only expansion memo only with xtrace enabled.
The expanded RHS remains available to tracing without executing it again.
The canonical scalar workload runs through the standalone-assignment path in
command_prepare.rs, not the memo insertion inapply_permanent_assignments.Memo gating alone therefore did not improve this workload: an initial 9-sample
run measured 1298.94 -> 1292.00 ms (0.5%, within observed noise), with unchanged
allocation counts. Do not attribute the scalar loop cost to that memo insert.
Method
Measured 2026-10-15 on Linux x86_64, WSL2 kernel
6.18.33.2-microsoft-standard-WSL2, glibc 2.39, Python 3.12.3.All Rubash binaries used the default release profile: opt-level 3, LTO,
one codegen unit. Reference: owner-built GNU Bash 5.3.0.
The native Linux Python parent performs two warmup rounds and nine measured
rounds, rotating baseline/candidate/reference order each round. Every invocation
has a 30-second timeout. Return code, stdout and stderr must match on every
run. Other agents paused builds and benchmarks for the measurement window.
Host scheduling still produced visible outliers; no wall-time speedup is claimed.
Reproduce with separately built release binaries from the two commits:
Raw local artifacts, including the diagnostic glibc allocation interposer:
target/issue-suites/results/issue-609/.linux-buffer-reuse.jsonrecords every sample, executable SHA256 and workloadSHA256. The interposer counts malloc/calloc/realloc calls and requested bytes;
it is a diagnostic, not a wall-time measurement, and is not used to time the runs.
Results
Scalar samples, milliseconds, in chronological order per binary:
Prefix samples:
The canonical scalar workload allocation counter was repeated three times:
This is approximately 600000 fewer allocator calls (8.82%), not an observed
wall-time improvement. Both stores remain; #609 is not resolved. Its <=1.2x
GNU wall-time target is not met. These Linux figures are not Android validation.
Semantic verification
paths and capacity/value consistency of the typed and mirror scalar cells.
indexed-array scalar assignment, nameref and local scope. Baseline and candidate
stdout/stderr are identical. The probe also exposed an existing associative
scalar-assignment defect: assigning key 0 loses another key in both Rubash
binaries but not GNU; this is not repaired or counted as passing GNU parity.
Performance PR acceptance
Do not close a performance issue merely because fmt, compilation or semantic
tests pass. Each performance PR must provide baseline/candidate commits, build
profile, fixed workload, machine/platform, reference binary, warmup, repeated
interleaved samples, median/min, output/exit equality and a clear acceptance
decision. Preserve inconclusive and regressing rows. Partial allocation savings
do not satisfy an outstanding wall-time target; keep the issue open.