Repository navigation
WIP: perf(F5): declare mark point queries + getopts window borrow - #1914
Merged
Merged
Conversation
…ll-table mark renders Every declare/typeset/local call materialized whole-table name sets per attribute key (VarTable::marked_names: iterate the attrs map, clone matching names, sort) and built HashSets from them, just to answer contains() for the command's own operands. A plain 'declare x=42' paid ~18 such renders; the cost scaled with the number of attributed variables in the shell (measured: 85.6us/op with the ambient environment, 345.2us/op with 300 extra exported variables, same-machine Linux), which is the F5 constant the 2026-10-28 perf round recorded (declare_assign 15.77x, declare_local_like 24.32x vs GNU 5.3.20). All membership consumers in the declare family now use VarTable::is_marked (one attr_of lookup; the same flag bits marked_names renders), including: - declare.rs: sync_typed_assignments / sync_typed_attributes operand checks, the nameref chain walk, the main operand loops - assign.rs: readonly gates, the per-element array check - attrs.rs: nameref target resolution, the visible-nameref skip filter, the unset-attribute branch - print.rs: declaration_line (state-view snapshots rendered ten sets per name), print_declare_names (the tempenv underlay is now consulted per name at print time - the same answers the snapshot-adjusted sets gave; listing-only candidate sets in declaration_names_to_print are unchanged, a listing walks the table anyway) Behavior is unchanged by construction (same underlying attribute map, point query vs render of the same set) and verified: declare/getopts shape corpora byte-identical to GNU bash 5.3.20, full declare -p listing corpus byte-identical old-vs-new (modulo the binary's own BASH/THIS_SH path), diffcorpus and the lib baseline unchanged. Measured (paired interleaved A/B, same machine, Linux): declare_assign 57.97 -> 19.21 us/op; with +300 exported variables 207.13 -> 22.69 us/op (table-size term gone); declare -p x 159.89 -> 52.61 us/op; bare declare 84.83 -> 24.37 us/op.
execute_getopts cloned the whole positional window (positional_window_cloned) on every call when no explicit args were given, making each call O($#): measured 459us/call scanning 3000 positionals vs 50us/call at 300 (same machine, Linux). The scan only reads the window - the current word is consumed into option_chars before any binding call, the separate-argument value is cloned at its read point, and args.len() is by-value - so the borrowed positional_window() slice serves every read. 3000-positional scan: 301.83 -> 22.42 us/op paired A/B.
caomengxuan666
marked this pull request as ready for review
October 28, 2026 05:35
caomengxuan666
added a commit
that referenced
this pull request
Oct 29, 2026
…#1951) Re-measurement verdict for the #1951 constant tax (full data in the cluster report): the ~0.29ms/line endpoint-specific tax measured at the audit freeze tip is gone on current master -- the streamed endpoint landed by rubash#1952 plus the F5 work (PR #1914) replaced the materialized endpoint it lived on. Same-window decomposition (Linux, same machine) now shows the while-read face tracking the engine's general per-command floor: the endpoint drains at external cat speed, and the shell-side read premium is source-independent (regular file, pipe and procsub within noise of each other). GNU's own pipe reads are byte-wise by design (read.def:668 sets unbuffered_read for pipe input; zreadc buffering covers the file face, where rubash already buffers), so no endpoint mechanism fix remains that would not either duplicate the floor-tax work tracked by rubash#682 / rubash#2005 or diverge from GNU. These two pins guard the re-measured face in CI: exact line count at 20k lines and whole, ordered records off the streamed endpoint.
This was referenced Oct 29, 2026
WIP: procsub drain faces — varredir_close completion close (#1646) + endpoint read tax (#1951)
#2017
Merged
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.
F5 family: declare / getopts per-call constants (perf round 2026-10-28, §5 F5)
Two mechanisms, both "cost must scale with the declaration's actual work, not table size / fixed pipeline":
1. declare/typeset/local — full-table mark renders per membership question.
Every call materialized whole-table name sets per attribute key (
marked_names: iterate the attrs map, clone matching names, sort) and builtHashSets from them, only to answercontains()for its own operands. A plaindeclare x=42paid ~18 renders. Measured mechanism proof (same machine, Linux): 85.6 µs/op ambient env → 345.2 µs/op with +300 exported variables. All membership consumers in the declare family now useVarTable::is_marked(oneattr_oflookup over the same flag bits). Listing paths that genuinely enumerate (declaration_names_to_print) are unchanged.2. getopts — positional window cloned per call.
execute_getoptscloned the entire positional window per call when no explicit args were given: 459 µs/call scanning 3000 positionals vs 50 µs/call at 300. All reads complete before the binding calls, so the borrowedpositional_window()slice now serves them.Behavior: zero change
-iarith, case attrs, array/assoc conversion + errors, nameref chains + errors, readonly, export/trace, function scope, subscript hints, PATH hash-flush, BASH_COMPAT hook; getopts silent/verbose, missing/unknown, attached/grouped args,--, OPTERR=0, OPTIND mid-stream, name=OPTARG): byte-identical to GNU bash 5.3.20, stdout+stderr, before and after.declare -plisting corpus (full + filtered listings,export -p/readonly -p, tempenv-prefixed listings, PIPESTATUS view, function scope, typeset): byte-identical old-vs-new (modulo the binary's ownBASH/THIS_SHpath lines).Measured (paired interleaved A/B, same machine, Linux, release)
declare x=42×5000declare -p x×1000declare x×5000Not in this PR (recorded in the cluster REPORT for homing)
The bench-shape
getopts_parseconstant is dominated by theOPTIND=1assignment statement (~+60–110 µs vs ~+0–20 for a plain bind): names excluded frombind_marks_free_scalar(OPTIND, integer-attributed, exported) pay the fullapply_shell_assignment_innerpath. That is the general assignment machinery — a separate family, not touched here.