Skip to content

⚡ Bolt: Optimize eBPF event parsing#193

Closed
blue4209211 wants to merge 1 commit into
mainfrom
bolt/optimize-ebpf-parsing-18014311665522767784
Closed

⚡ Bolt: Optimize eBPF event parsing#193
blue4209211 wants to merge 1 commit into
mainfrom
bolt/optimize-ebpf-parsing-18014311665522767784

Conversation

@blue4209211

Copy link
Copy Markdown
Contributor

💡 What: Replaced binary.Read with manual parsing (binary.LittleEndian) for eBPF events (l7Event, tcpEvent, fileEvent, procEvent). Moved parsing logic to ebpftracer/parsing.go.
🎯 Why: binary.Read uses reflection and allocates memory for the target struct. For l7Event, this meant allocating an 8KB struct on the heap for every event, causing high GC pressure and CPU usage.
📊 Impact: Expected to reduce heap allocations significantly (allocating only actual payload size instead of 8KB buffer) and improve event processing throughput.
🔬 Measurement: go test -v ./ebpftracer/... verifies correctness.


PR created automatically by Jules for task 18014311665522767784 started by @blue4209211

Replaced `binary.Read` with manual parsing using `binary.LittleEndian` to eliminate reflection overhead and reduce heap allocations, particularly for the large `l7Event` struct (8KB).

- Created `ebpftracer/parsing.go` with manual parsing functions.
- Added `ebpftracer/parsing_test.go` for verification.
- Updated `ebpftracer/tracer.go` to use the new parsing logic.
- Removed unused struct definitions from `tracer.go`.

Co-authored-by: blue4209211 <3078106+blue4209211@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @blue4209211, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly optimizes the processing of eBPF events by moving from reflection-based binary.Read to direct manual parsing. This change aims to drastically reduce memory allocations and CPU overhead, particularly for large event structures like l7Event, thereby improving the overall throughput and efficiency of event handling within the Bolt system. The parsing logic has been refactored into a new, dedicated file for better code organization and maintainability.

Highlights

  • Performance Optimization: Replaced binary.Read with manual parsing using binary.LittleEndian for eBPF events (l7Event, tcpEvent, fileEvent, procEvent) to reduce heap allocations and CPU usage.
  • Code Refactoring: Moved the eBPF event parsing logic into a new dedicated file, ebpftracer/parsing.go, improving modularity and separation of concerns.
  • Memory Efficiency: Specifically for l7Event, the change addresses the issue of binary.Read allocating an 8KB struct on the heap for every event, which caused significant garbage collection pressure.
  • New Test Coverage: Added a new test file, ebpftracer/parsing_test.go, to ensure the correctness of the newly implemented manual parsing functions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@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 is a great optimization. It replaces the use of binary.Read, which relies on reflection and can be slow and memory-intensive, with manual parsing using binary.LittleEndian. This significantly improves performance for eBPF event parsing, especially for l7Event which has a large buffer. The code is well-structured, with parsing logic cleanly extracted into a new parsing.go file and accompanied by thorough unit tests. I have a couple of suggestions to improve maintainability by removing magic numbers.

Comment thread ebpftracer/parsing.go
}

func parseL7Event(data []byte) (*Event, error) {
if len(data) < 56 {

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

To improve readability and maintainability, it's recommended to replace magic numbers with named constants. You could define constants for the header sizes of the different event types at the package level.

For example:

const (
    l7EventHeaderSize   = 56
    tcpEventSize        = 102
    fileEventSize       = 32
    procEventSize       = 12
)

This would make the size checks in parseL7Event, parseTCPEvent, parseFileEvent, and parseProcEvent more explicit and the code easier to maintain.

Comment thread ebpftracer/parsing.go

var response []byte
if responseSize > 0 {
start := 56 + 4096

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

The magic number 4096 is already defined as the exported constant MaxPayloadSize in tracer.go within the same package. Please use this constant to improve maintainability and avoid hardcoded values.

Suggested change
start := 56 + 4096
start := 56 + MaxPayloadSize

@mayankpande88

Copy link
Copy Markdown
Contributor

Closing — superseded by newer PRs (#196 for eBPF parsing, #194 for proc/net optimization).

@mayankpande88 mayankpande88 deleted the bolt/optimize-ebpf-parsing-18014311665522767784 branch May 27, 2026 07:07
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