Skip to content

speed up formatting and pattern compilation#93

Merged
lestrrat merged 7 commits into
masterfrom
perf-investigation
May 21, 2026
Merged

speed up formatting and pattern compilation#93
lestrrat merged 7 commits into
masterfrom
perf-investigation

Conversation

@lestrrat

Copy link
Copy Markdown
Collaborator
  • collapse zero-padded %H/%I into stdlib layout so the whole pattern combines into one time.AppendFormat call (cached path -23%)
  • index the specification set by a [256]Appender array instead of a map, dropping per-lookup hashing
  • append verbatim text inline on the uncached compile path, cutting Format() from 15 allocs to 1
  • cache compiled patterns in package-level Format() (bounded sync.Map, default-spec only), making repeated calls ~4x faster

Benchmarks (AMD Ryzen 9 7900X3D, go1.26.1): package-level Format() 820→206 ns/op (15→2 allocs); cached FormatBuffer 167→137 ns/op (0 allocs). All variants now beat ncruces/fastly/jehiah/tebeka.

@lestrrat lestrrat merged commit 2dde0bd into master May 21, 2026
13 checks passed
@lestrrat lestrrat deleted the perf-investigation branch May 21, 2026 08:05
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.

1 participant