Skip to content

perf(runner): order test functions in pure bash, drop 5 forks per file#809

Merged
Chemaclass merged 1 commit into
mainfrom
perf/functions-for-script-pure-bash
Jul 16, 2026
Merged

perf(runner): order test functions in pure bash, drop 5 forks per file#809
Chemaclass merged 1 commit into
mainfrom
perf/functions-for-script-pure-bash

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Continuing the fork-reduction series (#801-#808). Ground-truth profiling with a PATH shim (bash -x trace counts overcount by re-echoed test output) showed 7 awk + 2 sort forks per test file, dominated by discovery: functions_for_script ran an awk | sort | awk pipeline twice per file, and the duplicate check piped awk through sort.

💡 Changes

  • functions_for_script: filter + insertion-sort the file's functions by definition line in pure bash (a file's function list is tens of names); extdebug now enabled only inside the capture subshell, leaving the caller's setting untouched.
  • check_duplicate_functions: sort the (usually empty) duplicate list inside the awk END block instead of piping through sort.
  • 9 → 5 forks per test file; shim-based regression test + unit tests for ordering, cross-file filtering, and extdebug preservation. No behaviour change.

Two per-file fork clusters in discovery became pure bash / awk-internal:

- functions_for_script piped 'declare -F' through awk | sort | awk (three
  forks) and the pipeline ran twice per file. A file's function list is small
  (tens of names), so filter + insertion-sort by definition line in bash — and
  enable extdebug only inside the capture subshell so the caller's setting is
  untouched.
- check_duplicate_functions piped its awk pass through 'sort' just to keep the
  (usually empty) duplicate list deterministic; the awk END block sorts it now.

9 -> 5 forks per test file (awk 7 -> 5, sort 2 -> 0), on every file of every
run including the acceptance suite's ~258 nested ones. Measured with a PATH
shim: bash -x trace counts also pick up re-echoed test output and overcount.

No behaviour change.
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 16, 2026
@Chemaclass Chemaclass self-assigned this Jul 16, 2026
@Chemaclass Chemaclass merged commit 0ee8c62 into main Jul 16, 2026
37 checks passed
@Chemaclass Chemaclass deleted the perf/functions-for-script-pure-bash branch July 16, 2026 02:57
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