Skip to content

perf: decode values directly from row#795

Merged
olavloite merged 1 commit intomainfrom
decode-directly-from-row
Apr 14, 2026
Merged

perf: decode values directly from row#795
olavloite merged 1 commit intomainfrom
decode-directly-from-row

Conversation

@olavloite
Copy link
Copy Markdown
Collaborator

@olavloite olavloite commented Apr 14, 2026

Remove the intermediate step of first decoding a value to a GenericColumnValue, and then into the Go type that should be returned. This reduces the number of memory allocations needed to decode query results.

This is also needed for implementing https://pkg.go.dev/database/sql/driver#RowsColumnTypeScanType.

BenchmarkRows_Next_New-8        	     895	   1305352 ns/op	 1198360 B/op	   89750 allocs/op
BenchmarkRows_Next_Proto-8       	    1179	    991260 ns/op	  960408 B/op	   60006 allocs/op
BenchmarkRows_Next_Old-8   	             649	   1774592 ns/op	 1678361 B/op	  119750 allocs/op

(Note: The 'proto' option in the above table is the option where the row is not decoded at all, but just returns the proto value. That part was not changed in this pull request.)

@olavloite olavloite requested a review from a team as a code owner April 14, 2026 13:28
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes the Next method in rows.go by caching column types and utilizing direct column decoding, which minimizes the creation of intermediate GenericColumnValue objects. A potential nil pointer dereference was identified in the Next method if r.colTypes is accessed after a failed metadata initialization; it is recommended to add a check to handle this state safely.

Remove the intermediate step of first decoding a value to a GenericColumnValue,
and then into the Go type that should be returned. This reduces the number of
memory allocations needed to decode query results.
@olavloite olavloite force-pushed the decode-directly-from-row branch from 97e6f09 to 5198318 Compare April 14, 2026 13:52
@olavloite olavloite requested a review from rahul2393 April 14, 2026 14:07
@olavloite olavloite merged commit ed619ad into main Apr 14, 2026
43 checks passed
@olavloite olavloite deleted the decode-directly-from-row branch April 14, 2026 17:07
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