refactor(packetparser): reduce allocations in the hot path - #2508
Open
Matthew McKeen (mmckeen) wants to merge 2 commits into
Open
refactor(packetparser): reduce allocations in the hot path#2508Matthew McKeen (mmckeen) wants to merge 2 commits into
Matthew McKeen (mmckeen) wants to merge 2 commits into
Conversation
Matthew McKeen (mmckeen)
requested review from
skosuri1 and
Yilin (xiaozhiche320)
July 10, 2026 01:18
Matthew McKeen (mmckeen)
force-pushed
the
reduceFlowAllocations
branch
from
July 10, 2026 01:55
91769fb to
687069b
Compare
The metrics dispatch and each metric module independently re-unmarshaled the flow's structpb extensions on every accessor call, so a single flow's extensions were decoded ~4-5 times across the forward/tcpflags/latency/dns/drops modules. Decode the extensions once in the dispatch loop and thread the *structpb.Struct through ProcessFlow, reading fields via new utils.*FromStruct accessors. The existing flow-based accessors delegate to these, so behavior is unchanged; only the redundant per-flow unmarshals are removed. Signed-off-by: Matthew McKeen <matthew.mckeen@fastly.com>
The conntrack GC loop logged every map entry (up to CT_MAP_SIZE) on each tick, and the cache IP lookup logged on every flow. Both built the zap field slice and formatted IPs/strings eagerly at the call site even when debug logging is disabled, allocating on the hottest paths in production. Guard both with logger.Check(zap.DebugLevel) so the field construction and formatting are skipped entirely unless debug logging is enabled. Signed-off-by: Matthew McKeen <matthew.mckeen@fastly.com>
Matthew McKeen (mmckeen)
force-pushed
the
reduceFlowAllocations
branch
from
July 15, 2026 15:44
687069b to
91fe5fd
Compare
|
This PR will be closed in 7 days due to inactivity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Save some allocations by re-using the deserialized extensions struct in the hot path, also gate some debug only logs on log level where they are not needed.
Checklist
git commit -S -s ...). See this documentation on signing commits.Screenshots (if applicable) or Testing Completed
Deployed in test cluster, metrics are as before.
Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.