-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: optimize PacketType.classify fast path #70
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||
| ## YYYY-MM-DD - [PacketType.classify Optimization] | ||||||
| **Learning:** `PacketType.classify` is a small, frequently called utility function on the hot path (packet classification). In Zig, marking such functions with `inline` ensures the compiler eliminates function call overhead across module boundaries. Also, standard `switch` statements on integers compile to jump tables. Extracting the dominant case (data-plane packets, type 4) into an explicit `if` branch before the `switch` improves branch prediction and avoids jump table overhead. | ||||||
|
||||||
| **Learning:** `PacketType.classify` is a small, frequently called utility function on the hot path (packet classification). In Zig, marking such functions with `inline` ensures the compiler eliminates function call overhead across module boundaries. Also, standard `switch` statements on integers compile to jump tables. Extracting the dominant case (data-plane packets, type 4) into an explicit `if` branch before the `switch` improves branch prediction and avoids jump table overhead. | |
| **Learning:** `PacketType.classify` is a small, frequently called utility function on the hot path (packet classification). In Zig, marking such functions with `inline` can help the compiler eliminate function call overhead, even across module boundaries. Also, standard `switch` statements on integers may compile to jump tables. Extracting the dominant case (data-plane packets, type 4) into an explicit `if` branch before the `switch` can improve branch prediction and reduce potential jump table overhead. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,16 +24,20 @@ pub const PacketType = enum { | |||||||||
| stun, // STUN binding response | ||||||||||
| unknown, | ||||||||||
|
|
||||||||||
| pub fn classify(data: []const u8) PacketType { | ||||||||||
| /// Optimization: inline function and extract dominant case (data-plane packets) into an explicit fast-path to improve branch prediction and avoid jump table overhead. | ||||||||||
| pub inline fn classify(data: []const u8) PacketType { | ||||||||||
|
Comment on lines
+27
to
+28
|
||||||||||
| /// Optimization: inline function and extract dominant case (data-plane packets) into an explicit fast-path to improve branch prediction and avoid jump table overhead. | |
| pub inline fn classify(data: []const u8) PacketType { | |
| /// Optimization: extract dominant case (data-plane packets) into an explicit fast-path to improve branch prediction and avoid jump table overhead. | |
| pub fn classify(data: []const u8) PacketType { |
Copilot
AI
Mar 9, 2026
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.
The new doc comment asserts the switch has “jump table overhead”, but Zig/LLVM codegen isn’t guaranteed to lower this particular switch to a jump table (it may compile to compares/branches depending on optimization level/target). Suggest rewording to avoid relying on specific codegen details, and focus on the intent (dominant-case fast path) instead.
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.
This journal entry still has the
YYYY-MM-DDplaceholder in the header. Please replace it with the actual date (consistent with.jules/scribe.md/.jules/sentinel.md) so the log stays chronologically useful.