Skip to content

refactor: replace Split in loops with more efficient SplitSeq#2969

Open
box4wangjing wants to merge 1 commit intolabstack:masterfrom
box4wangjing:master
Open

refactor: replace Split in loops with more efficient SplitSeq#2969
box4wangjing wants to merge 1 commit intolabstack:masterfrom
box4wangjing:master

Conversation

@box4wangjing
Copy link
Copy Markdown

strings.SplitSeq (introduced in Go 1.23) returns a lazy sequence (strings.Seq), allowing gopher to iterate over tokens one by one without creating an intermediate slice.

It significantly reduces memory allocations and can improve performance for long strings.

More info: golang/go#61901

Signed-off-by: box4wangjing <box4wangjing@outlook.com>
@aldas
Copy link
Copy Markdown
Contributor

aldas commented May 10, 2026

Thanks, there are probably other places where this same logic could be applied - did you look for these also?

@box4wangjing
Copy link
Copy Markdown
Author

Thanks, there are probably other places where this same logic could be applied - did you look for these also?

Thank you for your reply. I’ve checked everything, and I only found this one case. @aldas

@aldas
Copy link
Copy Markdown
Contributor

aldas commented May 11, 2026

You could try grep -R --include="*.go" -A 5 "strings.Split" .

If think there are couple of places more where this change could be applied.

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