redis parser: avoid string conversions and reduce allocations on hot path#1481
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1481 +/- ##
==========================================
+ Coverage 43.98% 43.99% +0.01%
==========================================
Files 313 313
Lines 34353 34354 +1
==========================================
+ Hits 15110 15115 +5
+ Misses 18260 18255 -5
- Partials 983 984 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes the Redis detection/parsing hot path by reducing allocations and avoiding unnecessary string conversions, while extending the internal split iterator to support both string and []byte inputs.
Changes:
- Updated Redis request parsing to operate on
[]byteend-to-end (TCP and Go uprobe paths), avoiding buffer-to-string copies. - Refactored
split.Iteratorinto a generic iterator withNewStringIteratorandNewBytesIterator, and updated all call sites accordingly. - Optimized Redis error extraction and DB selection logic to reduce per-iteration conversions/allocations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/internal/split/splititerator.go | Makes Iterator generic over string/[]byte and adds typed constructors. |
| pkg/internal/split/splititerator_test.go | Updates string iterator tests and adds coverage for the new bytes iterator. |
| pkg/export/attributes/env.go | Switches env var parsing to NewStringIterator. |
| pkg/ebpf/common/http/sqlpp.go | Switches SQL++ parsing helpers to NewStringIterator. |
| pkg/ebpf/common/tcp_detect_transform.go | Removes request/response string(...) conversions when parsing Redis frames. |
| pkg/ebpf/common/redis_detect_transform.go | Updates Redis parsing to consume []byte, refactors error-prefix handling, and removes ToUpper allocation. |
| pkg/ebpf/common/redis_detect_transform_test.go | Updates Redis parsing tests to pass []byte inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Reduce unnecessary allocations and string conversions in the Redis
detection pipeline:
parseRedisRequestnow takes[]byteinstead ofstring, eliminatingthe buffer-to-string copy at both TCP call sites
(
string(requestBuffer.UnsafeView())). The Go Redis uprobe path alsodrops the
string(event.Buf[:])wrapper.split.Iteratoris made generic (Iterator[T string | []byte]) withtwo typed constructors:
NewStringIteratorandNewBytesIterator. Thebytes variant is used by
parseRedisRequestto iterate lines withoutany intermediate allocation. All existing string call sites are updated
to
NewStringIterator.redisErrorCodes [...]stringreplaced with aredisErrorsstruct arraypairing each
[]byteprefix with its pre-trimmedstringcode,eliminating the per-iteration
[]byte(code)conversion ingetRedisError. Description is now trimmed before string conversion(
string(bytes.Trim(...))), reducing the size of the allocation.getRedisDBreplacesstrings.ToUpperwithstrings.EqualFoldforthe SELECT/QUIT check, avoiding an allocation for the uppercased copy.
Checklist