Skip to content

perf(doc): parse assertion docs in a single awk pass#833

Merged
Chemaclass merged 2 commits into
mainfrom
feat/832-doc-single-awk-pass
Jul 19, 2026
Merged

perf(doc): parse assertion docs in a single awk pass#833
Chemaclass merged 2 commits into
mainfrom
feat/832-doc-single-awk-pass

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #832

bashunit doc took ~5.1s to print a text file: the doc parser forked an echo | sed pipe for every line of the ~1.6k-line assertion docs (plus a sed per printed docstring line, ~3200 forks). The acceptance suite paid it ~7 times, making one test file 29.7s.

💡 Changes

  • Rewrite the parser as a single awk pass with identical logic — output byte-identical (shasum-verified for doc and doc equals, dev and built binary)
  • bashunit doc ~5.1s → ~50ms; bashunit_test.sh 29.7s → 7.8s; full parallel suite ~24.5s → ~16.5s
  • Fork-census regression test: 0 sed forks on the doc path
  • Embedded-docs build marker (get_embedded_docs) untouched

https://claude.ai/code/session_01JSeB8UzLCpqst55hAK6dED

bashunit::doc::print_asserts looped over all ~1.6k lines of
docs/assertions.md and forked an 'echo | sed' pipe per line to detect
headings, plus another sed per printed docstring line — ~3200 forks and
~5.1s wall to print a text file. The acceptance suite paid it ~7 times
(snapshot + exit-code pairs and built-binary comparisons), making
bashunit_test.sh a 29.7s file.

One awk pass carries the identical logic (assert*/bashunit* heading
gate, literal substring filter, bracket/anchor stripping, code-fence
docstring emission): output is byte-identical (shasum-verified for
'doc' and 'doc equals', dev and built binary) and runs in ~50ms.

bashunit_test.sh 29.7s -> 7.8s; full parallel suite ~24.5s -> ~16.5s.
Fork-census regression test added (0 sed forks on the doc path).

Closes #832
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 19, 2026
@Chemaclass Chemaclass self-assigned this Jul 19, 2026
busybox awk (Alpine) rejects backslash-escaped brackets inside a
bracket expression, so the link-bracket gsub silently matched nothing
and doc output kept its markdown brackets. The []][ idiom is the
portable spelling; output stays shasum-identical on macOS/GNU awk.
@Chemaclass
Chemaclass merged commit 062014b into main Jul 19, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the feat/832-doc-single-awk-pass branch July 19, 2026 14:58
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