Skip to content

perf: lazy materialize function call arrays - #12

Merged
caomengxuan666 merged 1 commit into
masterfrom
codex/perf-expand-dispatch-hotspots
Jul 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
codex/perf-expand-dispatch-hotspots

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • Keep function call-stack arrays (FUNCNAME, BASH_ARGC, BASH_ARGV, BASH_LINENO, BASH_SOURCE) in executor memory and materialize their array storage only when read.
  • Avoid formatting/restoring those array variables on every shell function call.
  • Add a narrow assignment-value fast path for whole-value simple positional/special parameters and whole-value arithmetic expansion.
  • Execute function bodies through execute_ast_inner when already inside the executor lock.

Benchmarks

Release build, Windows, 80x80 repro scripts. Compared pristine origin/master after #11 against this branch; each row is median of 9 runs after warmup.

Script master this branch change
loop.sh 346.09 ms 347.59 ms +0.4%
arith.sh 401.66 ms 386.89 ms -3.7%
function-noop.sh 523.39 ms 430.38 ms -17.8%
function-args-arith.sh 824.77 ms 697.68 ms -15.4%

Tests

  • cargo fmt
  • Focused executor tests for function calls, command substitutions, call-stack arrays, arithmetic expansion side effects, positional expansion, assignment expansion, and tilde assignment behavior.
  • cargo build --release
  • cargo test --test executor_tests locally: 1356 passed; 3 failed with the same local PATH/Git Bash environment-sensitive failures seen on master:
    • test_exec_c_clears_external_command_environment
    • test_command_v_without_p_uses_current_path_for_external_command
    • test_command_without_p_uses_current_path_for_external_command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant