Repository navigation
fix(declare): render bare-listing function views lazily (Refs #3230) - #3982
Merged
Merged
Conversation
PR #3530 (for #3487) threaded pre-rendered FunctionSetViews through the set/declare funnels, and the executor materialized them at every dispatch: Executor::function_set_views() rendered every function's listing text via ast_print on each set/declare/typeset/local call, although only the bare-listing arm ever prints them. In a function-heavy shell (bats loads ~150 library functions and calls `local` pervasively) that is an O(total definition text) tax per call: on X299 (release) 2,000 local-carrying calls under 150 twelve-line functions took ~33 s, and bats' junit gather reported 221 ms/test against ~35 ms before the regression (bisect over 9ef7380..81a5bbf: first bad 3505855, the #3530 commit itself; #3177 is clean). GNU renders function definitions only inside print_all_shell_variables' print_func_list arm (builtins/set.def:506-527; variables.c:1079-1090), reached solely from the no-operand listing. Mirror that cost shape: the funnels now take a lazy FunctionSetViewProvider and realize the views only in the listing arm (set with no args; declare's plain arm). The render itself (Executor::render_function_set_views over the functions and function_def_infos maps) is unchanged. What this change deletes: the eager per-dispatch full-table render at five executor call sites (execute_set and the four declare/local routes in declare_local.rs). Verification (X299, release build of this branch): - probe (150 functions x 12 lines, local-loop x2000): 33 s -> 1 s - bats junit suite, direct form: 221/216 ms per test -> 37/37 ms (pre-#3177: 34/36 ms; #3177 itself: 35/37 ms) - bats junit outer form: 43 s -> 17 s wall, 9/9 ok (#3177: 17 s) - listing outputs (bare declare/set/typeset, -F/-f/-p/-a forms, POSIX mode, bare local, declare --) byte-identical to master except the self-referential BASH=<exe path> lines - new pin tests/issue3230_declare_family_lazy_views_regressions.rs (scaling-ratio sentinel + listing-arm checks): 2/2 green; issue3487 pin 9/9 green; builtins::set/declare lib tests 16/16 UNVERIFIED-BY-CAPTAIN
caomengxuan666
marked this pull request as ready for review
November 20, 2026 10:35
This was referenced Nov 20, 2026
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.
Refs #3230 — UNVERIFIED-BY-CAPTAIN
Root cause (bisect-adjudicated)
#3230's "post-#3177 pathological slowdown" is not #3177. Automatic bisect (good
9ef7380e= #3177 itself, bad81a5bbf7, oracle = bats per-test wall time) lands on35058553(PR #3530 for #3487, bare declare/set function-definition printing). That commit threaded a pre-rendered&[FunctionSetView]through the set/declare funnel;Executor::function_set_views()runs fullast_printrendering of every function definition, and five call sites (execute_set + four declare/local routes) materialized it eagerly on every dispatch — though only the bare-listing arms consume it. bats loads ~150 library functions and callslocalconstantly, so everylocalpaid O(total definition text).Measured on X299 (release): bats per-test 35/37 ms → 221/216 ms (~6.2×); 9-test file wall 17 s → 43 s; scaling probe (150 functions × 12-line bodies, 2000
localcalls) 0 s → 33 s.Fix
Match GNU's cost shape (only the print-all arm renders definitions; builtins/set.def, variables.c print_func_list): the funnel now takes a lazy
FunctionSetViewProvider(&dyn Fn() -> Vec<FunctionSetView>), materialized only inside the listing arms; rendering moved toExecutor::render_function_set_views(&functions, &function_def_infos). 7 source files +71/−25, plus new pin file.What this PR deletes
The eager materialization at all five dispatch sites; no fallback or dual path remains.
Evidence (lane, X299 release)
declare --) byte-identical master vs fixed except 5 self-referentialBASH=<exe path>lines.declareomits the function definitions GNU prints #3487 pins 9/9; set/declare lib tests 16/16; rustfmt clean.tests/issue3230_declare_family_lazy_views_regressions.rs: scaling sentinel per issue1119 convention (local-loop cost must not grow with function-table size; 20-vs-160 ratio bound 3×, 120 s absolute backstop). Its failure on the regression code is derived from the measurements above rather than separately re-run on a master build — disclosed here for the captain's verification.