Skip to content

Manual format string scanner replacing regex for messages with % #27

@alanzabihi

Description

@alanzabihi

Hypothesis

Replace the regex-based format string processing (common.js lines 90-107) with a manual single-pass character scanner using indexOf and charAt. This eliminates regex engine overhead for the 50% of calls that have format specifiers.

Rationale

For calls like log('request %s took %dms', url, time), the regex runs with a callback. A manual scanner that finds each % using indexOf, checks the next char, and builds the result via string concatenation should be faster since it avoids regex compilation, match object allocation, and callback invocation.

The scanner also naturally avoids args.splice by building a new args array in one pass.

Scope

  • src/common.js lines 90-107: replace regex.replace with manual indexOf-based scanner

Expected impact

Moderate. Eliminates regex engine overhead and callback allocation. Combines the benefits of thesis #2 (skip regex) and thesis #8 (avoid splice) for messages with format specifiers.

Risks

Must handle: %% escaping, unknown format letters, consecutive specifiers, trailing %, no remaining args. Fingerprint is the correctness check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions