Repository navigation
perf(for-arith): counter fast driver for canonical counting loops - #925
Merged
Merged
Conversation
… :; done` GNU owns the semantics: execute_arith_for_command (execute_cmd.c:3219) re-evaluates test/update via expr.c descent and dispatches the body via execute_command_internal per iteration, with line_number pinned to the for line (execute_cmd.c:3236) and DEBUG/REAP handling per iteration. For the canonical counter triple over one plain variable with a single bare-`:` body, every per-iteration effect is idempotent or provably unobservable mid-loop (no DEBUG action, trace, trap, job or failure can appear; the `:` body cannot arm any of them), so the driver performs the identical counter directly (i64 wrapping per bash_arith), the identical PostInc write pipeline (same record/sync calls, same order) and the identical net end-state (line/command stamps via the same helpers, `_`=`:` , exit 0). Whitelist admission only (rubash#117): counter shapes reuse the parse-cache gates, the body check mirrors #661 field-for-field, and any doubt (other operators/updates/bodies, non-canonical bounds, marked or dynamic loop variable, pending write log, installed trap action, xtrace, verbose, disabled/shadowed `:`, background jobs) runs the slow loop unchanged. Verified: 46-case bash differential battery (43 identical, 3 pre-existing GNU divergences byte-identical before/after), lib 645/0, cli 467/0. N=200k release best-of-3: empty loop 1038.7ms -> 131.3ms (0.21x bash); add loop unchanged (1.31x bash, slow path by design).
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.
Whitelist fast driver for for ((v=C0; v<C1; v++)) with bare : body (entry gates: slow-init ran, marks clean, empty write log, no traps, xtrace/verbose off, : not disabled, no jobtable/background children). Reuses parse-cache admission + PostInc write guards; i64 wrapping count, same observable state per round (i/_/exit/line keys), signal mailbox drained per 1024 rounds. GNU: execute_cmd arith-for + expr.c. Tests: lib 645 + cli 467 green; 46 bash diffs pass (3 diverges pre-existing, gated). Release N=200k empty body: 1038.7ms -> 131.3ms (0.21x bash).