Skip to content

perf: hoist timefmt parse layouts#105

Merged
sorafujitani merged 1 commit into
mainfrom
perf/timefmt-parse-cache
Jul 3, 2026
Merged

perf: hoist timefmt parse layouts#105
sorafujitani merged 1 commit into
mainfrom
perf/timefmt-parse-cache

Conversation

@sorafujitani

Copy link
Copy Markdown
Owner

Summary

  • hoist timefmt.Parse layouts out of the hot-path loop
  • add BenchmarkParse coverage for nano, second-precision, empty, and invalid inputs

Fixes #104

Benchmark

Command:

go test -bench=BenchmarkParse -benchmem ./internal/timefmt -count=10

benchstat /tmp/ccsession-104-before.txt /tmp/ccsession-104-after.txt:

Parse/RFC3339Nano-12   36.39n ± 2%   36.56n ± 3%       ~ (p=0.579 n=10)
Parse/RFC3339-12       23.84n ± 1%   23.56n ± 2%       ~ (p=0.183 n=10)
Parse/empty-12         1.824n ± 3%   1.808n ± 1%       ~ (p=0.796 n=10)
Parse/invalid-12       86.34n ± 1%   85.88n ± 1%       ~ (p=0.353 n=10)
geomean                19.23n        19.13n       -0.52%

Current Go already optimized the parse success paths to 0 B/op and 0 allocs/op before this change, so the measured allocation count is unchanged. The code still removes the per-call slice literal from the source-level hot path.

Verification

go test ./...
go vet ./...
golangci-lint run
gofmt -l $(git ls-files '*.go')
git diff --check

@sorafujitani sorafujitani merged commit 39a5cb2 into main Jul 3, 2026
7 checks passed
@sorafujitani sorafujitani deleted the perf/timefmt-parse-cache branch July 3, 2026 05:34
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.

perf: hoist per-call allocations in timefmt.Parse

1 participant