Skip to content

refactor(packetparser): reduce allocations in the hot path - #2508

Open
Matthew McKeen (mmckeen) wants to merge 2 commits into
microsoft:mainfrom
mmckeen:reduceFlowAllocations
Open

refactor(packetparser): reduce allocations in the hot path#2508
Matthew McKeen (mmckeen) wants to merge 2 commits into
microsoft:mainfrom
mmckeen:reduceFlowAllocations

Conversation

@mmckeen

Copy link
Copy Markdown
Contributor

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

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

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.

@mmckeen
Matthew McKeen (mmckeen) requested a review from a team as a code owner July 10, 2026 01:18
@mmckeen Matthew McKeen (mmckeen) changed the title perf(packetparser): reduce allocations in the hot path refactor(packetparser): reduce allocations in the hot path Jul 10, 2026
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>
@github-actions

Copy link
Copy Markdown

This PR will be closed in 7 days due to inactivity.

@github-actions github-actions Bot added the meta/waiting-for-author Blocked and waiting on the author label Aug 15, 2026
@nddq Quang Nguyen (nddq) removed the meta/waiting-for-author Blocked and waiting on the author label Aug 16, 2026
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