-
Notifications
You must be signed in to change notification settings - Fork 132
*: replace Split in loops with more efficient SplitSeq #4043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: wyrapeseed <wyrapeseed@outlook.com>
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4043 +/- ##
==========================================
- Coverage 53.79% 53.74% -0.06%
==========================================
Files 242 242
Lines 39412 39412
==========================================
- Hits 21203 21183 -20
- Misses 15967 15989 +22
+ Partials 2242 2240 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces strings.Split with strings.SplitSeq in loop iterations to improve memory efficiency. The SplitSeq function, introduced in Go 1.23, returns a lazy sequence that allows iterating over tokens without creating an intermediate slice, reducing memory allocations.
Key Changes
- Replaced
strings.Splitwithstrings.SplitSeqin four files where the result was immediately iterated over - Updated loop syntax from
for _, item := range strings.Split(...)tofor item := range strings.SplitSeq(...)
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/validatorapi/router.go | Updated query parameter parsing to use SplitSeq for comma-separated values |
| cmd/markdown_internal_test.go | Updated test file line iteration to use SplitSeq |
| app/log/config.go | Updated stack trace formatting to use SplitSeq for newline splitting |
| app/eth2wrap/genwrap/genwrap.go | Updated documentation parsing to use SplitSeq for newline splitting |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Thank you @wyrapeseed for the contribution! |
|
Thanks for your review. If there's anything need I to do, please feel free to let me know. |



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.
category: refactor
ticket: none