Skip to content

Encode time.Time dates and timestamps without a timeWrapper - #2728

Open
g4lb wants to merge 1 commit into
jackc:masterfrom
g4lb:time-encode-no-wrapper
Open

g4lb wants to merge 1 commit into
jackc:masterfrom
g4lb:time-encode-no-wrapper

Conversation

@g4lb

@g4lb g4lb commented Nov 22, 2026

Copy link
Copy Markdown

A time.Time for date, timestamp or timestamptz was boxed in a timeWrapper for each value. Now wrapTimeEncodePlan calls a new encodeTime method on the codec plan. Planning and the existing Encode methods do not change. The output does not change.

Benchmark Before After Allocs
timestamptz, binary 74.5 ns 39.0 ns 1 → 0
timestamptz, text 172.6 ns 123.9 ns 1 → 0
timestamp, binary 82.4 ns 40.5 ns 1 → 0
date, binary 131.8 ns 91.1 ns 1 → 0
[]time.Time (10), binary 931.5 ns 620.6 ns 22 → 12
pgtype.Timestamptz, binary 37.7 ns 38.1 ns 0 → 0

No benchmark got slower (AMD EPYC 7763, Go 1.27.4, 24 rounds).

Checks:

  • go test -race passes on PostgreSQL 18.
  • Old and new outputs matched on 1M values.

AI was used. I reviewed and tested the change, and I can answer questions on it.

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