perf: stream sampled profiles instead of loading every line #1094
No reviewers
Labels
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
No milestone
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!1094
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/stream-profile-input"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Replacement for #682 following the maintainer’s request to rebase on current
main. GitHub rejected reopening the closed PR after the branch history changed.scripts/prof.pyreads every line into memory before it aggregates samples, even whenskipis zero. Large captures can therefore use much more memory than the report needs.Stream the input in one pass when
skipis zero. For nonzeroskip, count physical lines and rewind before streaming the selected range. This preserves the existing slice behavior, symbol lookup, filters and report output.The branch is rebased on upstream
mainatac3bd44, which includes the answer-domain fixture repair (022ae80). The current CI runner discovers the newtests/test_profile_stream.pysuite automatically.python3 -I -B tests/run_all.py --strict profile_streampassed on macOS. The suite covers output, duplicate frames, skip and filter behavior, empty input, and symbol resolution.git diff --check upstream/main...HEADpassed.tracemallocfell from 11.16 MiB to 0.02 MiB.With nonzero
skip, the lower memory use requires a second pass over the input. AI assistance from OpenAI Codex is recorded in the commit trailers.The red "Python source checks" come from main at this branch's base, not from the change. On a merge of this branch with current main (
ac3bd44),tests/test_profile_stream.pypasses on Windows 11 with Python 3.12, alone and throughtests/run_all.py profile. I have not tried it on a real capture yet.Looks good to me. I walked through the new
profile_linesagainst the oldreadlines()slice and the behaviour matches:skip == 0streams straight through. Nonzeroskipcounts physical lines first, so blank lines still count before the filter, exactly as before.lines[int(len(lines) * skip):], and the tests cover those cases.main(), so nothing else needs the list. The report output code is unchanged.withblocks, the encoding anderrors="replace"are unchanged, and text mode keeps the same newline handling for\r\nand a last line with no newline.scripts/prof.pyon main is identical to this PR's base, so there are no conflicts. The new test is picked up by the runner automatically, and the checks I saw are green.One optional nit: with a nonzero
skipthe file now has to be seekable, so it won't work on a pipe like/dev/stdinany more. The old code did. That's fine for a tool that readsstacks.txtfrom a run directory, but you could mention it in the docstring if you like.