Skip to content

gh-150662: Stop unbounded memory growth in Tachyon --gecko collector#150845

Merged
pablogsal merged 9 commits into
python:mainfrom
maurycy:gecko-ad-inf
Jun 6, 2026
Merged

gh-150662: Stop unbounded memory growth in Tachyon --gecko collector#150845
pablogsal merged 9 commits into
python:mainfrom
maurycy:gecko-ad-inf

Conversation

@maurycy
Copy link
Copy Markdown
Contributor

@maurycy maurycy commented Jun 3, 2026

The PR fixes an unbounded memory growth caused by:

for t in times:
samples_stack.append(stack_index)
samples_time.append(t)
samples_delay.append(None)

It was reported in gh-150662 and the detailed idea for the fix by @pablogsal:

#150662 (comment)

Discussion

I don't think others collector have this issue. pstats, collapsed/flamegraph, heatmap, jsonl should just plateau. I've reviewed them. I pondered this for a day, and I don't think there's a better fix? It's not really crash-resillent safe. It likely doesn't matter here that much, as I'm really not sold on using Gecko for really long term profiling. Binary format is much better in this regard, and I've started experimenting with a different fix there. Perhaps we should encourage recording binary pattern more? The tests stay as is.

(No longer) Reproduction

2026-06-03T13:48:12.219584000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (gecko-ad-inf fcfb002*) % ./python.exe -c "
def work(): return sum(i*i for i in range(2000))
while True: work()
" & TARGET=$!

sudo ./python.exe -m profiling.sampling attach --gecko -r 10000 -d 900 -o /tmp/gecko.json $TARGET &
sleep 2; PROF=$(pgrep -fn "profiling.sampling attach")
for i in $(seq 15); do printf "t=%2dmin  RSS=%d MB\n" $i $(($(ps -o rss= -p $PROF|tr -d ' ')/1024)); sleep 60; done
[1] 80893
[2] 80894
t= 1min  RSS=30 MB
t= 2min  RSS=30 MB
t= 3min  RSS=30 MB
t= 4min  RSS=30 MB
t= 5min  RSS=30 MB
t= 6min  RSS=30 MB
t= 7min  RSS=30 MB
t= 8min  RSS=30 MB
t= 9min  RSS=30 MB
t=10min  RSS=30 MB
t=11min  RSS=30 MB
t=12min  RSS=30 MB
t=13min  RSS=30 MB
t=14min  RSS=30 MB
t=15min  RSS=30 MB
Captured 9,000,001 samples in 900.00 seconds
Sample rate: 10,000.00 samples/sec
Error rate: 27.59
Gecko profile written to /tmp/gecko.json
Open in Firefox Profiler: https://profiler.firefox.com/

[2]  + done       sudo ./python.exe -m profiling.sampling attach --gecko -r 10000 -d 900 -o  

Visual validation

https://profiler.firefox.com/

image

Comment thread Lib/profiling/sampling/gecko_collector.py Outdated
Comment thread Lib/profiling/sampling/gecko_collector.py
Comment thread Lib/profiling/sampling/gecko_collector.py
Copy link
Copy Markdown
Member

pablogsal commented Jun 6, 2026

Thanks, this looks really good ❤️

I pushed a couple of fixups that just clean up the implementation and tests: the spill state now lives with each thread, the JSON streaming path is a bit less repetitive, cleanup is centralized, and the tests now exercise forced spill flushing, column alignment, export failure behavior, and the one-shot lifecycle.

Nice work tracking this down and keeping the memory behavior flat 💪

@pablogsal pablogsal enabled auto-merge (squash) June 6, 2026 02:03
@pablogsal pablogsal added the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 6, 2026
@pablogsal pablogsal merged commit 785b6dc into python:main Jun 6, 2026
58 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @maurycy for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Jun 6, 2026

GH-151000 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 6, 2026
@maurycy maurycy deleted the gecko-ad-inf branch June 6, 2026 04:48
pablogsal pushed a commit that referenced this pull request Jun 6, 2026
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.

2 participants