Skip to content

store: replace binary.Write with binary.BigEndian.PutUint64 in encodeSortableInt64#343

Merged
bootjp merged 3 commits intofeature/dynamodbfrom
copilot/sub-pr-342
Mar 13, 2026
Merged

store: replace binary.Write with binary.BigEndian.PutUint64 in encodeSortableInt64#343
bootjp merged 3 commits intofeature/dynamodbfrom
copilot/sub-pr-342

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 13, 2026

encodeSortableInt64 was using bytes.NewBuffer + binary.Write, introducing a heap allocation and reflection overhead on every call in a hot-path helper, while silently discarding the write error.

Changes

  • store/list_helpers.go: Replace allocation-heavy pattern with a direct, zero-allocation binary.BigEndian.PutUint64 write:
// Before
buf := bytes.NewBuffer(dst[:0])
_ = binary.Write(buf, binary.BigEndian, seq^math.MinInt64)

// After
binary.BigEndian.PutUint64(dst, uint64(seq^math.MinInt64))

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 13, 2026 15:19
Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
…SortableInt64

Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on storing DynamoDB schemas as protobuf store: replace binary.Write with binary.BigEndian.PutUint64 in encodeSortableInt64 Mar 13, 2026
Copilot AI requested a review from bootjp March 13, 2026 15:23
@bootjp bootjp marked this pull request as ready for review March 13, 2026 15:35
Comment thread store/list_helpers.go
}
buf := bytes.NewBuffer(dst[:0])
_ = binary.Write(buf, binary.BigEndian, seq^math.MinInt64)
binary.BigEndian.PutUint64(dst, uint64(seq^math.MinInt64))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
G115: integer overflow conversion int64 -> uint64 (gosec)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot fix it

@bootjp bootjp merged commit 26647e3 into feature/dynamodb Mar 13, 2026
5 checks passed
@bootjp bootjp deleted the copilot/sub-pr-342 branch March 13, 2026 15:41
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