Skip to content

All formatArgs optimizations: prefix cache, newline guard, humanize cache, suffix pre-build #34

@alanzabihi

Description

@alanzabihi

Hypothesis

Combine all proven formatArgs-level optimizations into one change. Prior attempts on the Hetzner node showed 13-16% improvements but the absolute metrics did not beat the current best (104.62ms) due to hardware differences. A contributor on faster hardware applying these same optimizations should see proportional gains.

IMPORTANT: The current main branch includes thesis #1 (Date.now) and thesis #2 (indexOf fast-path). Your baseline when you run bench on current main should be around 104ms (on fast hardware) or 280ms (on Hetzner). Your metric must beat 104.62 in absolute terms.

Changes to combine

  1. Pre-compute _colorCode and _colorPrefix at init (from thesis Pre-compute ANSI color prefix per instance at init time #5/Combined: cache color prefix, short-circuit newline, cache humanize, lazy prev/curr #23)
  2. indexOf newline guard before split/join (from thesis Short-circuit split/join for single-line messages in formatArgs #6/Combined: cache color prefix, short-circuit newline, cache humanize, lazy prev/curr #23)
  3. ms.humanize cache keyed on this.diff (from thesis Cache ms.humanize result for identical consecutive diffs #12/Combined: cache color prefix, short-circuit newline, cache humanize, lazy prev/curr #23)
  4. Pre-compute suffix start (colorCode + 'm+') at init (new, from thesis Avoid string concat in suffix: pre-build colorCode+'m+' prefix once #33 direction)

Scope

  • src/node.js init(): cache _colorCode, _colorPrefix, _suffixStart, _lastDiff, _lastHumanized
  • src/node.js formatArgs(): use all cached values

Expected impact

On the Hetzner node these combined changes showed 47ms improvement (16.5%). Proportionally on the Mac Mini (~104ms baseline), that would be ~17ms improvement to ~87ms.

Risks

Low. All changes are independent and within formatArgs/init only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions