Skip to content

Format integers with strconv in getFieldAsString - #313

Open
g4lb wants to merge 1 commit into
gocarina:masterfrom
g4lb:strconv-integers
Open

g4lb wants to merge 1 commit into
gocarina:masterfrom
g4lb:strconv-integers

Conversation

@g4lb

@g4lb g4lb commented Nov 4, 2026

Copy link
Copy Markdown

getFieldAsString now formats integers with strconv, not fmt.Sprintf. The output does not change.

Benchmark Before After Change
Benchmark_MarshalCSVWithoutHeaders 274.5 ns 246.3 ns -10.3%
100 rows, small values 44.05 µs 30.88 µs -29.9%
100 rows, large values 96.97 µs 79.14 µs -18.4%

The 100-row benchmarks are mine and are not in this PR. I used 14 interleaved rounds and benchstat (Apple M5, Go 1.26.5).

One slowdown: a direct call on a nil pointer is 0.3 ns slower (+17%). This path does not run the changed lines, and unrelated padding removes the difference. The cause is probably code layout. Rows of only nil pointers show no significant change.

go test -race ./... passes. Old and new outputs matched on 1,005,328 inputs.

I found this change with autor3search.

fmt.Sprintf boxes each value. strconv.FormatInt and FormatUint do the
same work directly. The output does not change.
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