Repository navigation
gh-159207: Bound Tachyon replay memory on Linux and Windows - #162580
Merged
pablogsal merged 4 commits intoNov 25, 2026
Merged
Conversation
Replay maps the whole profile into memory and asks the kernel to load every page up front. Those pages stay resident until the reader is closed, so memory usage grows with the size of the capture, even though replay only needs one block at a time. Stop preloading the file and let pages load on demand as replay reads them. On Linux, release the string and frame tables once they have been parsed, and release each sample block once it has been replayed. Only pages that have been fully consumed are released. Because the mapping is read-only, a released page is read back from the file if it is needed again.
On Windows, opening a profile reads the whole file into memory and keeps it there until the reader is closed. Memory usage therefore grows with the size of the capture, even though replay only needs one block at a time. Read only the header and the tables that follow the samples when the profile is opened. The tables are parsed into their own structures, so the bytes read for them are released straight away. During replay, read the samples through a small reusable window that always holds at least one complete block, keeping the unread bytes and refilling the rest from the file as blocks are consumed. Memory used for samples is then bounded by the window size rather than by the length of the capture.
pablogsal
requested changes
Nov 24, 2026
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
pablogsal
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After #160313, Tachyon decodes samples one block at a time during replay, so only a small portion of the sample data needs to be in memory at once. However, the reader still keeps the entire profile file in memory: on Linux, it maps the whole file and loads all of its pages up front, while on Windows it reads the complete file into a single buffer. As a result, replay memory still grows with the size of the profile, despite samples being decoded in bounded blocks.
This change makes the reader keep only the parts of the profile that replay currently needs. When opening a profile, it reads the header and the shared string and frame tables, then reads sample data one block at a time during replay. Once a block has been replayed, its memory can be released. On Linux, the reader tells the kernel that the pages for completed blocks can be dropped; on Windows, sample blocks are read into a small reusable buffer instead of loading the entire file.
With this change, replaying a 332 MB profile peaks at around 42 MB of memory instead of 355 MB, while producing the same output with no meaningful change in replay time.