Skip to content

Conversation

@analytically
Copy link
Contributor

Replace zero-fill + overwrite pattern with direct byte appends. Use array pointer cast in SetInt32 to eliminate bounds checks.

Benchmarks show 12-19% improvement in message building:
BindMessage5Params: 164 ns → 132 ns (19% faster)
BindMessage20Params: 922 ns → 780 ns (15% faster)
Simulate10kQueries: 1.37ms → 1.21ms (12% faster)

Assembly comparison for SetInt32:
Before: 134 bytes, 4 bounds checks, 4 panicIndex calls
After: 63 bytes, 1 bounds check, 1 panicSliceConvert call

No functional changes. All existing tests pass.

Replace zero-fill + overwrite pattern with direct byte appends.
Use array pointer cast in SetInt32 to eliminate bounds checks.

Benchmarks show 12-19% improvement in message building:
  BindMessage5Params:  164 ns → 132 ns  (19% faster)
  BindMessage20Params: 922 ns → 780 ns  (15% faster)
  Simulate10kQueries: 1.37ms → 1.21ms  (12% faster)

Assembly comparison for SetInt32:
  Before: 134 bytes, 4 bounds checks, 4 panicIndex calls
  After:   63 bytes, 1 bounds check,  1 panicSliceConvert call

No functional changes. All existing tests pass.
@jackc jackc merged commit 2b6baa7 into jackc:master Jan 1, 2026
14 checks passed
@jackc
Copy link
Owner

jackc commented Jan 1, 2026

Thanks

@analytically analytically deleted the perf/pgio branch January 2, 2026 19:02
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