Skip to content

gh-156545: Fix flamegraph export RecursionError on deeply recursive programs - #156546

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:gh-156545-flamegraph-deep-stack
Open

gh-156545: Fix flamegraph export RecursionError on deeply recursive programs#156546
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:gh-156545-flamegraph-deep-stack

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

FlamegraphCollector.export() walks the flamegraph tree recursively (convert_children) and serializes it with json.dumps, both bounded by the depth of the deepest sampled stack. Since the unwinder can capture up to 1536 frames while export runs at the default recursion limit (1000), profiling a deeply recursive program made export() raise RecursionError and produce no flamegraph.

Raise the recursion limit by a bounded margin (covering the unwinder's cap) while exporting, restoring it in finally. The fix is in the base FlamegraphCollector.export, so --diff-flamegraph is covered too; the collapsed / JSONL / Gecko exporters are iterative and unaffected.

The added test fails without the fix (RecursionError) and passes with it; test_profiling passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant