Skip to content

perf: avoid hot command bookkeeping - #11

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

caomengxuan666 merged 1 commit into
masterfrom
codex/perf-function-dispatch

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • store shell function bodies as shared ASTs and clone only when redirects need to rewrite the body
  • avoid syncing __RUBASH_CURRENT_FUNCTION to the process environment on every function call
  • make $BASH_COMMAND text construction lazy, including a guard for indirect ${!ref} access
  • update __RUBASH_CURRENT_LINE in the process environment only for builtins that still read diagnostics from std::env

Profiling notes

  • Tried Windows Performance Recorder, but this machine is blocked by policy: Failed to enable the policy to profile system performance.
  • Tried samply, but Windows ETW processing failed locally with an invalid handle.
  • Used temporary internal timing instrumentation, then removed it before this PR. That pointed to per-command bookkeeping inside execute_command rather than arithmetic evaluation as the dominant hot path.

Benchmarks

Release build, 7 runs each, median wall time on the local Windows machine:

script baseline patched change
loop 448.28 ms 330.83 ms -26.2%
arith 519.30 ms 428.06 ms -17.6%
function-noop 732.08 ms 545.44 ms -25.5%
function-args-arith 1126.39 ms 827.02 ms -26.6%

Tests

  • cargo fmt
  • cargo test --test executor_tests bash_command
  • cargo test --test executor_tests test_function
  • cargo test --test executor_tests test_shift
  • cargo test --test executor_tests test_readonly
  • cargo build --release
  • cargo test --test executor_tests still has the same 3 local PATH/Git Bash environment failures seen on baseline:
    • command_chaining::part_038::test_exec_c_clears_external_command_environment
    • command_chaining::part_043::test_command_v_without_p_uses_current_path_for_external_command
    • command_chaining::part_044::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