From 61af8ec1074de705f0903d25823c7fff23866673 Mon Sep 17 00:00:00 2001 From: Alexander Timin Date: Thu, 22 Aug 2024 17:19:32 +0100 Subject: [PATCH] Use indexes for flow table It's very typical to filter the flow table on either `slice_in` or `slice_out`. Having an index for some traces speeds slice selection from 22s to 300ms for some slices with flows. Change-Id: If3d889b25b78ac1f9f9e282a53a5a3c28b68cf41 --- src/trace_processor/perfetto_sql/stdlib/slices/flow.sql | 9 +++++++++ ui/src/controller/flow_events_controller.ts | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/trace_processor/perfetto_sql/stdlib/slices/flow.sql b/src/trace_processor/perfetto_sql/stdlib/slices/flow.sql index f93947859f..4741de1235 100644 --- a/src/trace_processor/perfetto_sql/stdlib/slices/flow.sql +++ b/src/trace_processor/perfetto_sql/stdlib/slices/flow.sql @@ -15,6 +15,15 @@ INCLUDE PERFETTO MODULE graphs.search; +-- It's very typical to filter the flow table on either incoming or outgoing slice ids. +-- +-- Ideally, this should be automatic and shouldn't require any additional imports, however we +-- can't add it to prelude (because it is initialised before the trace is loaded and the indexes +-- are not rebuilt when the new data is loaded), so the interested parties should remember to import +-- this module. +CREATE PERFETTO INDEX flow_in ON flow(slice_in); +CREATE PERFETTO INDEX flow_out ON flow(slice_out); + -- Computes the "reachable" set of slices from the |flows| table, starting from slice ids -- specified in |source_table|. This provides a more efficient result than with the in-built -- following_flow operator. diff --git a/ui/src/controller/flow_events_controller.ts b/ui/src/controller/flow_events_controller.ts index b2e3d18c96..d6e1cd5077 100644 --- a/ui/src/controller/flow_events_controller.ts +++ b/ui/src/controller/flow_events_controller.ts @@ -315,6 +315,9 @@ export class FlowEventsController extends Controller<'main'> { : `directly_connected_flow(${sliceId})`; const query = ` + -- Include slices.flow to initialise indexes on 'flow.slice_in' and 'flow.slice_out'. + INCLUDE PERFETTO MODULE slices.flow; + select f.slice_out as beginSliceId, t1.track_id as beginTrackId,