Skip to content

perf(coverage): scan function declarations in one awk pass - #1085

Merged
Chemaclass merged 1 commit into
mainfrom
perf/1084-extract-functions-awk
Aug 13, 2026
Merged

Chemaclass merged 1 commit into
mainfrom
perf/1084-extract-functions-awk

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1084

extract_functions walked each source file in Bash, counting braces with two
pattern substitutions per line — 17.5 ms per file against a 3.5 ms fork floor,
and the report phase pays it once per file per renderer.

💡 Changes

  • The same state machine runs as one awk pass; rules unchanged, quirks included
  • extract_functions 2238 ms → 399 ms over 128 files, report_lcov 5052 ms → 2638 ms, and a --coverage run over src 9.23 s → 6.81 s
  • Output diffed against the Bash implementation over all 463 shell files in the repo, and the LCOV report is byte-identical on a fixed corpus
  • Characterization tests pin the spans that carry the risk: nested braces, single-line bodies, every declaration spelling, an unclosed body at EOF, and shapes that are not declarations

extract_functions walked each file in Bash and counted braces with two
pattern substitutions per line: 17.5ms per file against a 3.5ms fork floor,
paid once per file per renderer. The same state machine in awk is 2238ms to
399ms over 128 files, and report_lcov 5052ms to 2638ms.

The rules are unchanged, quirks included, and the output was diffed against
the Bash implementation over all 463 shell files in the repo. The
characterization tests pin the spans that carry the risk: nested braces,
single-line bodies, every declaration spelling, an unclosed body at EOF and
the shapes that are not declarations.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant