google / google/perfetto

Reduce amalgamated C SDK source size

Open
#5,799 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
6.5k
Forks
868
Avg merge
2d 1h
Merged PRs (30d)
218

Description

`tools/gen_amalgamated --sdk c` currently produces ~12 MB / 290k lines of source. Most of it is dead weight: per-domain trace + config protos and a handful of C++ files that the C ABI under `include/perfetto/public/abi/` never references. They're pulled in transitively via the GN dep graph (`recurse_in_header_deps` walks `:zero|cpp` even when nothing `#include`s them) and via `cppgen_plugin`'s `[lazy = true]` skip not being transitive.

I have a working set of changes that:
- adds `enable_perfetto_minimal_trace_protos` (default off, auto-on for `--sdk c`)
- gates per-domain trace/config/common proto deps behind it
- extends `cppgen_plugin`'s lazy-import skip to walk transitively
- gates `src/tracing/{console_interceptor,track_event_state_tracker,track_event_legacy}.cc` and `src/base/{cpu_info,ctrl_c_handler,getopt_compat,subprocess*}.cc` (all unreachable from the C ABI)

Result on the C SDK build (no public API change, no impact on `--sdk cpp` / `--sdk all` / chromium / Android / standalone):

| | Before | After |
|---|---:|---:|
| `perfetto_c.{cc,h}` | 12.0 MB | **5.6 MB (-54%)** |
| Stripped `.so` (`-O2 -fvisibility-inlines-hidden`) | 2.69 MB | **2.22 MB (-17%)** |
| `clang++ -O2 -c` wall time | 37.1 s | 30.1 s (-19%) |

@LalitMaganti @primiano Are we interested in making this improvement? If yes I'll prepare them for review (6 small commits).

Contributor guide

Open the contributing guide

Research direction

Start with tools/gen_amalgamated --sdk c and the GN dependency graph described in the issue, then inspect the C ABI under include/perfetto/public/abi/. Trace how cppgen_plugin handles lazy imports and review the listed src/tracing and src/base files. Done means the C SDK keeps its public API while reaching the reported smaller source, binary, and compile-time results without changing other SDK builds.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp
Domain
build-system, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.