Skip to content

perf(assert): reduce lowercase forks in assert_contains_ignore_case #845

Description

@Chemaclass

Problem

assert_contains_ignore_case (src/assert.sh, ~lines 293-320) lowercases both operands with a printf | tr pipe each — 2 subshell forks per call:

expected_lower=$(printf '%s' "$expected" | tr '[:upper:]' '[:lower:]')
actual_lower=$(printf '%s' "$actual"   | tr '[:upper:]' '[:lower:]')

Lower priority than #844 (this assertion is less common), but same class of avoidable per-call fork.

Bash 3.0+ constraint (why the obvious fixes are out)

  • ${var,,} — Bash 4.0+. Forbidden.
  • shopt -s nocasematch — Bash 3.1+. Forbidden (hard floor is 3.0; CI runs a 3.0 job).
  • So tr stays the portable lowercasing tool.

Possible fixes (pick the one that measures best and stays 3.0-safe)

  1. Collapse two forks into one — lowercase both operands in a single tr pass over a delimited string, then split. Saves one fork per call.
  2. Herestring instead of pipetr ... <<< "$s" avoids the printf subshell (one fork instead of two per operand). Confirm <<< behavior on Bash 3.0.
  3. Leave as-is if neither is a clean, provable win — acceptable outcome; document why.

Do NOT regress correctness for a micro-fork. Bench first.

Acceptance criteria

  • Fork count per call reduced, or a documented decision to keep as-is.
  • assert_contains_ignore_case behavior unchanged (existing tests green; add one if the lowercase path is under-covered).
  • ./bashunit tests/ + ./bashunit --parallel --simple --strict tests/ green.
  • make sa, make lint, ./build.sh --verify green.
  • Before/after micro-benchmark in the PR.
  • Bash 3.0+ compatible (no ${var,,}, no nocasematch, no printf -v).

Metadata

Metadata

Assignees

Labels

refactoringRefactoring or cleaning related

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions