Skip to content

perf(memtrack): stop capturing stacks on free - #558

Merged
not-matthias merged 2 commits into
mainfrom
cod-3703-eval-performance-overhead-of-memory-flamegraphs
Oct 1, 2026
Merged

not-matthias merged 2 commits into
mainfrom
cod-3703-eval-performance-overhead-of-memory-flamegraphs

Conversation

@not-matthias

Copy link
Copy Markdown
Member

Why

Memory flamegraphs only attribute allocations. The platform's memtrack-parser unwinds stacks attached to Free events and caches the callchain, but only allocation samples are folded, so free stacks are never read.

With stack capture on by default, every free() still paid the full capture: an 8 KiB user-stack copy, the FNV hash, bpf_get_stackid, and (since exact-hash dedup is ~0% effective) a full record into the stack ring. That is roughly half of all captures.

What

  • free uprobe no longer calls capture_stack; submit_free_event drops the hash.
  • MemtrackEventKind::Free is a unit variant. The serialized form is unchanged (stack_hash was already skipped when zero), and artifacts written by older memtrack versions with a stack_hash on frees still decode (covered by legacy_free_with_stack_hash_decodes).
  • Stack test snapshots print Free without the has_stack flag.

Expected effect

About half the stack captures, stack ring writes, encode CPU, and archive stack bytes on allocation-heavy benchmarks; less unwinding work in callgraph generation. To be measured on the platform memory shards (COD-3703).

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Memory tracking stops capturing stack traces on free operations.

The PR is not ready to merge because a near-limit Memory or WallTime profile can fail upload without a compression attempt.

Summary

The PR removes stack capture from free events and makes Free a unit variant. Changes since the previous review also export a run ID as a GitHub Actions step output and enforce a 5 GiB profile-archive limit.

  • The archive limit has a boundary case that can reject a compressible profile without attempting compression.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Memory or WallTime profile folder] --> B{Folder at least 5 GiB?}
  B -- Yes --> C[Create gzip tar]
  B -- No --> D[Create uncompressed tar]
  C --> E{Archive over 5 GiB?}
  D --> E
  E -- Yes --> F[Abort upload]
  E -- No --> G[Upload archive]
Loading

Reviews (4) · Last reviewed commit: "refactor(memtrack): drop stack_hash from..."

@not-matthias
not-matthias force-pushed the cod-3703-eval-performance-overhead-of-memory-flamegraphs branch from 96e3091 to 6a35299 Compare September 30, 2026 14:49
@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 19.2%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 1 improved benchmark
✅ 32 untouched benchmarks
⏩ 4 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ WallTime memtrack track tar 9.4 s 7.9 s +19.2%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cod-3703-eval-performance-overhead-of-memory-flamegraphs (c01f5d2) with main (fabf8e4)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@greptile-apps

This comment has been minimized.

@GuillaumeLagrange GuillaumeLagrange left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

olgtm

Comment thread crates/runner-shared/src/artifacts/memtrack/mod.rs Outdated
Memory flamegraphs only attribute allocations: the platform unwinds free
stacks and never reads the result. Capturing them doubled the per-event
probe cost, the stack ring traffic, and the archive's stack bytes.

The Free event no longer carries a stack_hash. Artifacts from older memtrack
versions that still have the field decode unchanged.

Refs COD-3703
Free events no longer carry a stack, and the stack_hash field on Free was never part of a release (v5.3.1 ships Free as a unit variant). Revert Free to a unit variant instead of keeping a deprecated always-zero field, and update callers, tests, and snapshots.
@not-matthias
not-matthias force-pushed the cod-3703-eval-performance-overhead-of-memory-flamegraphs branch from 381195e to c01f5d2 Compare October 1, 2026 09:34
@not-matthias
not-matthias merged commit c01f5d2 into main Oct 1, 2026
57 checks passed
@not-matthias
not-matthias deleted the cod-3703-eval-performance-overhead-of-memory-flamegraphs branch October 1, 2026 09:49
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