Skip to content

gh-159207: Bound Tachyon replay memory on Linux and Windows - #162580

Merged
pablogsal merged 4 commits into
python:mainfrom
ivonastojanovic:tachyon-reader-bounded-memory
Nov 25, 2026
Merged

pablogsal merged 4 commits into
python:mainfrom
ivonastojanovic:tachyon-reader-bounded-memory

Conversation

@ivonastojanovic

Copy link
Copy Markdown
Contributor

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.

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 pablogsal left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Ivona. Good work on this. I think we are close. The main change I want before merge is to cap the Windows buffer at the sample size for small profiles. I left a few smaller comments inline.

@bedevere-app

bedevere-app Bot commented Nov 24, 2026

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@pablogsal pablogsal left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the update, Ivona! One small docs nit.

@pablogsal
pablogsal enabled auto-merge (squash) November 25, 2026 21:50
@pablogsal
pablogsal merged commit 2005753 into python:main Nov 25, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage topic-profiling type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants