Skip to content

tp: rename blocking calls module and optimize for CUJs#6093

Open
gopi3587 wants to merge 3 commits into
mainfrom
dev/gelanchezhian/rename-blocking-calls
Open

tp: rename blocking calls module and optimize for CUJs#6093
gopi3587 wants to merge 3 commits into
mainfrom
dev/gelanchezhian/rename-blocking-calls

Conversation

@gopi3587
Copy link
Copy Markdown

@gopi3587 gopi3587 commented Jun 1, 2026

Renames the standard library module to android.blocking_calls_during_cujs and the internal table to _android_blocking_calls_during_cujs.

Restructures the stdlib table using strict CROSS JOIN top-down indexing to scope queries directly to process IDs with active CUJs. This completely bypasses unindexed scans over the global slice table.

By traversing the join path from active processes down to individual track slices, the query optimizer can leverage the B-Tree indices on thread tracks and slice track IDs, providing massive reductions in slices evaluated and cutting query latency.

Furthermore, this locks the optimal execution plan in-place, permanently preventing the SQLite query planner from degenerating into unindexed nested-loop cartesian scans, which previously caused severe wall-clock regressions on developer workstations.

All baseline and optimized outputs remain character-for-character binary-identical (verified via host trace_processor_shell benchmark sweeps).

Test: manual verification via trace_processor_shell benchmark sweeps

Welcome to Perfetto!
Make sure your PR has a bug/issue attached or has at least
a clear description of the problem you are trying to fix.

For more details please see
https://perfetto.dev/docs/contributing/getting-started

Renames the standard library module to `android.blocking_calls_during_cujs`
and the internal table to `_android_blocking_calls_during_cujs`.

Restructures the stdlib table using strict CROSS JOIN top-down
indexing to scope queries directly to process IDs with active CUJs.
This completely bypasses unindexed scans over the global slice
table.

By traversing the join path from active processes down to
individual track slices, the query optimizer can leverage the
B-Tree indices on thread tracks and slice track IDs, providing
massive reductions in slices evaluated and cutting query latency.

Furthermore, this locks the optimal execution plan in-place,
permanently preventing the SQLite query planner from degenerating
into unindexed nested-loop cartesian scans, which previously
caused severe wall-clock regressions on developer workstations.

All baseline and optimized outputs remain character-for-character
binary-identical (verified via host trace_processor_shell
benchmark sweeps).

Test: manual verification via trace_processor_shell benchmark sweeps
Flag: EXEMPT METRICS
Change-Id: I9306ec79ffafb81e51a36ddb64cf3d533b67dfca
@gopi3587 gopi3587 requested a review from a team as a code owner June 1, 2026 16:43
@LalitMaganti
Copy link
Copy Markdown
Member

LalitMaganti commented Jun 1, 2026

Sorry but this is not the correct fix at all. The module was designed very intentionally to separately compute the blocking calls, the cujs and then a layer on top to compose them. This is because you can reason about blocking calls outside of CUJs perfectly fine.

You are hardcoding a hack to some particular problem you're having rather than solving the problem more correctly in a general way.

@gopi3587
Copy link
Copy Markdown
Author

gopi3587 commented Jun 1, 2026

Ack, working on the cleanup without impacting the existing tables and their dependencies.

@gopi3587 gopi3587 force-pushed the dev/gelanchezhian/rename-blocking-calls branch 5 times, most recently from 85666c7 to 9c159ad Compare June 4, 2026 05:53
Introduces a new standard library module `android.blocking_calls_during_cujs`
(and table `_android_blocking_calls_during_cujs`) that optimizes blocking
call extraction specifically for processes involved in active SystemUI CUJs.

By pre-filtering by relevant UPIDs and enforcing a strict top-down indexed
join sequence via `CROSS JOIN` (relevant_upids -> process -> thread ->
thread_track -> slice), SQLite query execution plans are locked against
optimizer regressions, permanently avoiding full scans of the global slice table.

To preserve backward compatibility, the original standard library module
`android.critical_blocking_calls` and the generic unaggregated metric
`android_blocking_calls_unagg` remain completely unchanged and generic.
Only the CUJ-scoped metrics are migrated to the optimized table.

Optimization & Testing Summary:
Performance and output correctness were validated using the large trace set
and all 12 scenario traces. In all cases, outputs are 100% character-for-character
identical to the baseline.

1. Large Trace (abc.perfetto-trace, 168MB) - Both Metrics Processed Together:
   - Baseline Time: 20.130s
   - Optimized Time: 10.500s
   - Speedup: 1.92x (47.84% total processing time saved)
   - Output Validation: 100% Match (SUCCESS)

2. Scenario Traces (Batch sweep, 12 traces, 450MB cumulative) - Both Metrics Together:
   - Total Baseline Time: 49.720s
   - Total Optimized Time: 27.519s
   - Cumulative Speedup: 1.81x (44.65% overall processing time saved)
   - Individual Trace Speedups: 1.48x to 2.03x
   - Output Validation: 100% Match across all 12 files (SUCCESS)

Test: manual verification via trace_processor_shell benchmark sweeps
Test: tools/check_sql_modules.py --check-includes
@gopi3587 gopi3587 force-pushed the dev/gelanchezhian/rename-blocking-calls branch from 9c159ad to 460844a Compare June 4, 2026 05:57
Copy link
Copy Markdown
Author

@gopi3587 gopi3587 left a comment

Choose a reason for hiding this comment

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

Created a new blocking calls during CUJ's without impact the previous generic implementation.

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.

3 participants