Skip to content

perf(runner): use 'wait -n' for parallel job slot when available #667

@Chemaclass

Description

@Chemaclass

Context

bashunit::runner::wait_for_job_slot (src/runner.sh:136-160) polls jobs -r | wc -l with adaptive 50ms→200ms sleep to detect free slots. Each poll forks a subshell for jobs -r | wc -l and adds wakeup latency on test completion.

Proposal

When Bash >= 4.3 (supports wait -n), block on next-child-exit instead of polling:

if [ "\${BASH_VERSINFO[0]}" -gt 4 ] || { [ "\${BASH_VERSINFO[0]}" -eq 4 ] && [ "\${BASH_VERSINFO[1]}" -ge 3 ]; }; then
  while [ "\$(jobs -r | wc -l)" -ge "\$max_jobs" ]; do
    wait -n 2>/dev/null || break
  done
else
  # existing poll loop (Bash 3.0 fallback)
fi

Eliminates sleep latency and reduces jobs -r invocations.

Acceptance

  • wait -n path used on Bash 4.3+
  • Existing poll path preserved as Bash 3.0 fallback
  • Parallel suite throughput improved (benchmark in PR)
  • No deadlock when no jobs running
  • Sync + parallel suites green

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestrefactoringRefactoring or cleaning related

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions