Skip to content

perf: reduce string normalization overhead - #3

Merged
cmilesio merged 1 commit into
mainfrom
perf/reduce-string-normalization-overhead
Jul 17, 2026
Merged

perf: reduce string normalization overhead#3
cmilesio merged 1 commit into
mainfrom
perf/reduce-string-normalization-overhead

Conversation

@cmilesio

Copy link
Copy Markdown
Member

What

  • Uses strings.TrimSpace for Trim so ASCII inputs take the standard-library fast path.
  • Reworks NormalizeSpace around canonical-input detection and single-allocation ASCII/Unicode builders.
  • Preserves Unicode and invalid-UTF-8 behavior without retaining oversized source buffers.
  • Adds comparative fluent/stdlib benchmarks and stronger normalization fuzz coverage.

Why

The fluent wrapper itself inlines without adding allocations. The measurable cost was inside whitespace normalization.

Case Before After
Trim ASCII ~12.8 ns ~2.9 ns
NormalizeSpace ASCII ~370 ns, 552 B, 7 allocs ~114 ns, 48 B, 1 alloc
NormalizeSpace Unicode ~370 ns, 552 B, 7 allocs ~200 ns, 48 B, 1 alloc
Already normalized ~354 ns, 552 B, 7 allocs ~27 ns, 0 allocs

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cmilesio
cmilesio merged commit e096e9a into main Jul 17, 2026
2 checks passed
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