Skip to content

tp: move trace processor to FlatHashMapV2 - #7854

Draft
LalitMaganti wants to merge 1 commit into
mainfrom
dev/lalitm/tp-flat-hash-map-v2
Draft

LalitMaganti wants to merge 1 commit into
mainfrom
dev/lalitm/tp-flat-hash-map-v2

Conversation

@LalitMaganti

Copy link
Copy Markdown
Member

Summary

Moves trace processor's maps to FlatHashMapV2, except a few hot ones
which measured slower on it. The FlatHashMap alias, used by the rest
of Perfetto, stays on FlatHashMapV1.

Why

FlatHashMapV2 (a Swiss table) is faster than FlatHashMapV1 for general
workloads, and after the parent PR generates less code.

Changes

  • Every base::FlatHashMap in src/trace_processor becomes
    base::FlatHashMapV2, including the StringPool's string index.
  • Five maps stay on FlatHashMapV1, with a comment: args dedup
    (GlobalArgsTracker::arg_row_for_hash_), track interning
    (TrackTracker::tracks_), slice stacks (SliceTracker::stacks_) and
    thread lookups (ProcessTracker::tids_, live_tid_). They are hit on
    every event, and FlatHashMapV2 stores each value next to its key, so
    large values or a large table of small padded slots cost more cache
    misses than V1's separate arrays. Profiles of a funcgraph trace put
    these at a ~6% load-time regression on FlatHashMapV2.

Benchmarks

trace_processor_shell, Linux x64, min of 5 interleaved runs, vs main:

Trace Load Load + queries
trace_500mb.pftrace (ftrace) -2.3% -1.1%
post_boot_trace.atr -0.8% -0.5%
ui-funcgraph.pftrace 0.0% -0.4%

Peak RSS within 2%. Stripped binary: -67 KB.

Testing

Only benchmarks so far: query results are identical to main on the
three traces above. FlatHashMapV2 iterates in a different order to
FlatHashMapV1, so tests whose output depends on map iteration order may
need updating.

@LalitMaganti
LalitMaganti requested a review from a team as a code owner October 8, 2026 21:40
@LalitMaganti
LalitMaganti added this pull request to stack #7855 October 8, 2026 21:42
@LalitMaganti
LalitMaganti force-pushed the dev/lalitm/tp-flat-hash-map-v2 branch from 064be0c to a4e9be9 Compare October 8, 2026 22:26
@LalitMaganti
LalitMaganti marked this pull request as draft October 8, 2026 22:33
@LalitMaganti
LalitMaganti force-pushed the dev/lalitm/tp-flat-hash-map-v2 branch from a4e9be9 to 03efd70 Compare October 8, 2026 22:33
@LalitMaganti
LalitMaganti force-pushed the dev/lalitm/tp-flat-hash-map-v2 branch from 03efd70 to da8aa6e Compare October 8, 2026 22:57
@LalitMaganti
LalitMaganti force-pushed the dev/lalitm/tp-flat-hash-map-v2 branch from da8aa6e to 45e38e0 Compare October 8, 2026 23:10
Base automatically changed from dev/lalitm/fhm-v2-code-size to main October 9, 2026 16:56
@LalitMaganti
LalitMaganti force-pushed the dev/lalitm/tp-flat-hash-map-v2 branch from 45e38e0 to 44597a1 Compare October 9, 2026 16:58
FlatHashMapV2 (a Swiss table) is faster than FlatHashMapV1 in our
benchmarks for general workloads and now generates less code, so move
trace processor's maps over to it, including the StringPool's string
index. The FlatHashMap alias, used by the rest of Perfetto, stays on
FlatHashMapV1.

A few maps stay on FlatHashMapV1, with a comment: those looked up on
every event of a trace whose lookups measured slower on FlatHashMapV2
(args dedup, track interning, slice stacks and thread lookups). V2
stores each value next to its key, so large values or a large table of
small padded slots cost more cache misses than V1's separate arrays.

Load and load+query times vs before, Linux x64 (min of 5 runs):
  trace_500mb.pftrace (ftrace)  -2.3% / -1.1%
  post_boot_trace.atr           -0.8% / -0.5%
  ui-funcgraph.pftrace           0.0% / -0.4%
trace_processor_shell stripped: -67KB.
@LalitMaganti
LalitMaganti force-pushed the dev/lalitm/tp-flat-hash-map-v2 branch from 44597a1 to 9e20a97 Compare October 9, 2026 21:03

This branch has not been deployed

No deployments
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.

1 participant