Skip to content

store: replace bytes.NewBuffer+binary.Write with binary.BigEndian.PutUint64 in encodeSortableInt64#346

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

store: replace bytes.NewBuffer+binary.Write with binary.BigEndian.PutUint64 in encodeSortableInt64#346
bootjp merged 2 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 to encode an int64 — introducing a buffer allocation and reflection overhead for a hot, low-level path.

Changes

  • store/list_helpers.go: Replace bytes.NewBuffer + binary.Write with binary.BigEndian.PutUint64, writing directly into the caller-provided dst slice with zero allocations.
// 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.

… allocation

Co-authored-by: bootjp <1306365+bootjp@users.noreply.github.com>
Comment thread store/list_helpers.go
// binary.Write cannot fail here: the payload is a fixed-size int64 and the
// destination is an in-memory bytes.Buffer.
_ = 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

[store/list_helpers.go](https://github.com/bootjp/elastickv/pull/346/files/2d154bbf6fbfe55bc48c7b9aefde5d9fcbe72a8a#diff-715a1b973fd34b80452d5d8c2d31d72ddb3d181d329a8b15ae900ecb0d8f8f10)
	// binary.Write cannot fail here: the payload is a fixed-size int64 and the
	// destination is an in-memory bytes.Buffer.
	_ = binary.Write(buf, binary.BigEndian, seq^math.MinInt64)
	binary.BigEndian.PutUint64(dst, uint64(seq^math.MinInt64))
@[github-actions](https://github.com/apps/github-actions)
github-actions bot
[1 minute ago](https://github.com/bootjp/elastickv/pull/346#discussion_r2932213358)
🚫 [golangci] reported by [reviewdog](https://github.com/reviewdog/reviewdog) 🐶
G115: integer overflow conversion int64 -> uint64 (gosec)

Copilot AI changed the title [WIP] [WIP] Address feedback from review on storing DynamoDB schemas as protobuf store: replace bytes.NewBuffer+binary.Write with binary.BigEndian.PutUint64 in encodeSortableInt64 Mar 13, 2026
Copilot AI requested a review from bootjp March 13, 2026 16:04
@bootjp bootjp marked this pull request as ready for review March 13, 2026 16:06
@bootjp bootjp merged commit a4aa902 into feature/dynamodb Mar 13, 2026
5 checks passed
@bootjp bootjp deleted the copilot/sub-pr-342 branch March 13, 2026 16:06
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