Skip to content

Modernize pkg#12722

Open
dveeden wants to merge 2 commits into
pingcap:masterfrom
dveeden:modern_pkg
Open

Modernize pkg#12722
dveeden wants to merge 2 commits into
pingcap:masterfrom
dveeden:modern_pkg

Conversation

@dveeden

@dveeden dveeden commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #12691

What is changed and how it works?

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

None

@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. affect-ticdc-config-docs Pull requests that affect TiCDC configuration docs. labels Jun 16, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign maxshuang for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 16, 2026

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

Copy link
Copy Markdown

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 modernizes the codebase by adopting Go 1.21+ features, including replacing interface{} with any, utilizing for range loops, adopting slices.Contains and maps.Copy, and refactoring goroutine management with sync.WaitGroup helpers. Additionally, tests are updated to use t.Context(). The feedback suggests further optimizing the HexKey function in pkg/spanz/convert.go by using hex.EncodeToString and strings.ToUpper instead of a loop with fmt.Sprintf and strings.Builder.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/spanz/convert.go
Comment on lines 29 to 36
func HexKey(key []byte) string {
// TODO(qupeng): improve the function.
str := ""
var str strings.Builder
for _, c := range key {
str += fmt.Sprintf("%02X", c)
str.WriteString(fmt.Sprintf("%02X", c))
}
return str
return str.String()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using fmt.Sprintf in a loop to convert a byte slice to a hex string is highly inefficient because it involves reflection, parsing the format string, and multiple allocations per byte. Since there is already a TODO to improve this function, we can implement it much more efficiently using the standard library's hex.EncodeToString and strings.ToUpper.

Note: You will need to import "encoding/hex" in this file.

func HexKey(key []byte) string {
	// TODO(qupeng): improve the function.
	return strings.ToUpper(hex.EncodeToString(key))
}

@dveeden

dveeden commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

/cc @kennytm @GMHDBJD

@ti-chi-bot ti-chi-bot Bot requested review from GMHDBJD and kennytm June 16, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affect-ticdc-config-docs Pull requests that affect TiCDC configuration docs. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant