Skip to content

perf: P0 performance optimizations#598

Merged
Chemaclass merged 6 commits intomainfrom
perf/p0-performance-optimizations
Mar 6, 2026
Merged

perf: P0 performance optimizations#598
Chemaclass merged 6 commits intomainfrom
perf/p0-performance-optimizations

Conversation

@Chemaclass
Copy link
Member

Summary

  • Reorder clock fallback: Prioritize EPOCHREALTIME (shell variable, no subprocess) over Perl/Python/Node. Eliminates ~188 subprocess calls per full test run on Bash 5.0+ systems.
  • Cache function discovery: Pass pre-computed function list to avoid duplicate declare -F | awk | sort | awk pipeline per test file. Saves ~100+ process spawns during test discovery.
  • Reduce subshells in hot path: Replace state getter subshells and grep-based assertion counting with direct variable reads and parameter expansion. Eliminates ~6 subshell forks per test (~5000 total).
  • Batch coverage recording: Replace per-line file I/O with in-memory buffers (flush every 100 records) and in-memory caches for should_track/normalize_path. Reduces I/O by ~99% when coverage is enabled.

Test plan

  • All 830 tests pass (./bashunit tests/)
  • ShellCheck passes (make sa)
  • EditorConfig lint passes (make lint)
  • Clock tests updated for new priority order
  • Coverage tests updated for buffered writes

…ations

Reorder clock fallback chain to check EPOCHREALTIME (shell variable,
no subprocess) first, then date +%s%N, before spawning Perl/Python/Node.
Eliminates ~188 subprocess calls per full test run on Bash 5.0+ systems.
Pass pre-computed function list from load_test_files to
call_test_functions, eliminating a redundant declare -F | awk | sort | awk
pipeline per test file. Saves ~100+ process spawns during test discovery.
Replace state getter subshells with direct variable reads and
replace grep-based assertion counting with parameter expansion.
Eliminates ~6 subshell forks per test (~5000 total for full suite).
Replace per-line file I/O with in-memory buffers that flush every 100
records. Add in-memory caches for should_track decisions and normalized
paths, eliminating grep subprocesses and cd/pwd forks from the DEBUG
trap hot path. Reduces I/O by ~99% when coverage is enabled.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

✅ Contributor Report

User: @Chemaclass
Status: Trusted contributor (whitelisted)

This user is on the trusted contributors list and was automatically approved.

@Chemaclass Chemaclass self-assigned this Mar 6, 2026
…rder

The clock _choose_impl now tries EPOCHREALTIME and date before perl,
so tests for perl and python must mock the earlier fallbacks to prevent
them from being selected first.
@Chemaclass Chemaclass enabled auto-merge (squash) March 6, 2026 02:53
@Chemaclass Chemaclass merged commit 87aadbe into main Mar 6, 2026
21 of 22 checks passed
@Chemaclass Chemaclass deleted the perf/p0-performance-optimizations branch March 6, 2026 21:54
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.

2 participants