Skip to content

perf: reuse loop execution ASTs - #10

Merged
caomengxuan666 merged 1 commit into
masterfrom
codex/perf-nested-loop-optimization
Jul 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
codex/perf-nested-loop-optimization

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • Reuse the arithmetic-for loop body AST across iterations instead of cloning it every pass.
  • Reuse normalized while/until condition and body ASTs across iterations.
  • Reduce repeated allocation and normalization overhead in nested-loop workloads without changing execution order or loop-depth handling.

Benchmarks

Measured with the existing nested-loop repro scripts under release builds on Windows, comparing pristine origin/master (68b8024) against this branch:

  • loop baseline: 995.8, 718.6, 634.9 ms; patched: 531.9, 536.4, 535.8 ms
  • arith baseline: 796.9, 758.8, 772.1 ms; patched: 713.0, 737.1, 674.9 ms
  • function-noop baseline: 1051.4, 1048.2, 1020.2 ms; patched: 978.3, 992.6, 933.6 ms
  • function-args-arith baseline: 1658.2, 1710.4, 1654.6 ms; patched: 1550.7, 1497.7, 1523.4 ms

Tests

  • cargo fmt
  • Focused executor tests:
    • test_function_body_can_be_while_command_sequence
    • test_pipeline_feeds_while_command_stage
    • test_function_assignment_arithmetic_expansion_accepts_base_hash
    • test_arithmetic_for_loop
    • test_arithmetic_for_command
    • test_while_command
    • test_time_prefix_executes_while_command_sequence

Note: full cargo test --test executor_tests fails locally on both this branch and pristine origin/master with the same 3 PATH/environment-sensitive tests that unexpectedly resolve C:\Program Files\Git\bin\bash.exe.

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