Files
d80692b99e feat(tools): rebase and polish rerunnable GC baseline tool (#2852, follow-up to #2949) (#3190)
* feat(tools): commit the GC baseline measurement as a rerunnable tool

The GC section of #2852 came from an ad-hoc script that was never committed, so
its numbers cannot be reproduced. This is that method in the repo.

It counts GC-tracked objects, times full-generation collections, and attributes
the cost to the pre-existing heap with gc.freeze(). Phases keep only scalars:
holding references between them would shift the very counters being measured,
and the type summary is a histogram rather than a list of objects.

--load imports modules first (sets in tools/profiles/gc-baseline.json). Without
it a run only sees interpreter boilerplate -- 9.7k objects and 2.8 ms, versus
239k objects and 137 ms with the Core import chain, which is where the population
actually comes from. A failing preload is reported, not fatal.

--saveall names unreachable types. It changes collector behavior, so its timing
is reported separately; DEBUG_SAVEALL also has to be enabled before the collect
or the earlier settling collect has already freed what it wants to name.

Verified on this host: the tool reproduces the issue's shape (large long-lived
population, scan cost dominated by it, 0 objects collected per scan). 16 new
tests, whole tools suite 190 passed, ruff clean.

Co-authored-by: antmultica-agent <agent@antmultica.alipay.com>

* docs(tools): stop calling the core profile the #2852 baseline

`core` lands around 240k tracked objects while the issue measured ~1.04M, so the
profile description claiming it "matches the complete load condition" invited
exactly the wrong comparison.

Correct the description and add a `load-complete` profile that is actually close:
Core plus the LLM client stack and the heavy platform SDKs reaches ~730k here
(the issue also had the plugin runtime and every adapter). Bare/core/load-complete
now differ by an order of magnitude, so the README says to quote the profile next
to any number. A test pins that every profile is valid, documented, and that
`core` no longer claims to be the baseline.

Co-authored-by: antmultica-agent <agent@antmultica.alipay.com>

* feat(tools): wire gc_baseline profiles, compare command, and contract tests

Follow-up polish on top of #2949 rebased onto latest master:

- Wire --profile and --profiles-file into gc_baseline measure so shipped sets
  in tools/profiles/gc-baseline.json are directly runnable and recorded in
  reports; deduplicate combined --profile + --load module lists.
- Add top_function_modules histogram (scalar counts only) and a compare
  subcommand that diffs two measure --json reports while warning on platform,
  profile, or preload mismatches and avoiding fabricated zero deltas for
  outside-top-N histogram entries.
- Reclaim sampled cycles in saveall_type_sample() after clearing gc.garbage,
  rename scalar saveall duration field to duration_ms, render saveall top_types
  in text summaries, record frozen_objects in freeze_attribution(), and avoid
  duplicating src in sys.path.
- Fix false-green freeze_attribution exception test to verify unfreeze calls
  and gc.get_freeze_count(), and expand contract tests to 28 passing cases.

Co-authored-by: antmultica-agent <agent@antmultica.alipay.com>

* fix(tools): harden GC baseline comparison boundaries

Co-authored-by: antmultica-agent <agent@antmultica.alipay.com>

* style(tools): format GC baseline fixes

Co-authored-by: antmultica-agent <agent@antmultica.alipay.com>

---------

Co-authored-by: TyperBody <marcelacelani74@gmail.com>
Co-authored-by: antmultica-agent <agent@antmultica.alipay.com>
2026-11-28 19:52:35 +08:00
..