Title: gh-159207: Store Tachyon samples in bounded columnar blocks by ivonastojanovic · Pull Request #160313 · python/cpython · GitHub
Open Graph Title: gh-159207: Store Tachyon samples in bounded columnar blocks by ivonastojanovic · Pull Request #160313 · python/cpython
X Title: gh-159207: Store Tachyon samples in bounded columnar blocks by ivonastojanovic · Pull Request #160313 · python/cpython
Description: Tachyon's binary format currently stores all samples in a single compressed stream. Each record contains its thread and interpreter IDs, timestamp, status, and stack change, so values such as the thread and interpreter IDs are written repeatedly across records. The existing RLE encoding avoids some of this when a stack repeats, and compression reduces it further, but the format still mixes fields with very different patterns in the same stream. More importantly, this means replay has to decompress the complete sample stream before it can process the first sample. The temporary buffer therefore grows with the length of the capture, even though replay only needs a small part of the sample data at a time. This PR changes the binary format to split samples into bounded, independently decodable blocks. Replay can decompress and process one block at a time, then reuse the same buffers for the next block. Within each block, sample fields are also separated into columns, allowing repeated values to be removed before compression and each type of data to use an encoding that better matches its structure. This change focuses on profiles exported to regular files. Live streaming remains separate work in #145464. Regular files can keep shared string and frame tables at the end of the file, while a live stream cannot refer to tables that have not been sent yet. For streaming, we may instead need to include the required string and frame data in each block so that it can be decoded as soon as it arrives. Implementation The new file layout is: header | sample block | sample block | ... | string table | frame table | stats | footer Each sample block has its own header followed by six columns: block header | stream table | stream IDs | timestamp residuals | status bitmaps | stack instructions | frame IDs Samples keep their original order across these columns, but no longer need a complete record containing every field. Values shared across a block move into its header or tables, while the per-sample columns only store what changes. The block header contains the sample count, base timestamp, frame-ID width, status masks, and the size and encoding of each column. Column What it stores What this avoids Stream table Each (thread_id, interpreter_id) pair used by the block, once Repeating both full IDs in every record Stream IDs A small stream-table index for each sample Carrying the full thread and interpreter IDs with each sample Timestamp residuals Difference from the expected timestamp for that stream Storing larger timestamp differences alongside other fields Status bitmaps One bitmap for each status bit that varies Writing one complete status byte per sample; common bits are stored once in the header Stack instructions How to repeat, change, or reuse a stack Writing frames that are unchanged or already available in the block Frame IDs Referenced frame-table indices at the smallest width needed by the block Using a larger representation for every frame ID The writer first reserves space for the file header. It then collects samples into a block and starts a new one when the decoded column data reaches 1 MiB or the block reaches 4,096 unique (thread_id, interpreter_id) pairs. Once sampling finishes, it writes the shared string and frame tables, statistics, and footer, then seeks back to fill in the file header. Strings and frames remain shared across the whole file, preserving deduplication across the complete capture. These tables still grow with the number of unique strings and frames, but temporary decoded sample data is now bounded by the size of one block rather than the total number of samples. Timestamp and stack state are tracked independently for each stream. Timestamps are stored as residuals from the expected timestamp, so samples arriving at the normal interval usually store zero. Status bits shared by all samples in a block are stored once in the block header, while only varying bits need per-sample bitmaps. Stacks use three instructions: Instruction Operands Meaning REPEAT count Reuse this stream's previous stack for count samples REPLACE_SUFFIX keep_count, new_count Keep the common outer frames and append new_count frame IDs REUSE offset, count Copy a complete stack already stored in the block's frame-ID column REPEAT is tracked per stream, so samples from other streams can appear between repetitions. The other instructions either write only the frames that changed or reuse a complete stack already stored in the block. Frame IDs use between one and four bytes and are stored in byte planes to improve compression. Each column is stored as raw bytes, a single repeated byte, or zstd level 3, whichever is smallest. The file-wide string and frame tables still use raw storage; compressing them is left for a follow-up. After discussing this with @pablogsal, we decided not to keep support for version 1 profiles since this change will be shipped in 3.16. The public BinaryWriter, BinaryReader, and collector APIs remain unchanged, except that the get_stats() dictionaries now report reuse_records instead of pop_push_records, since the pop-push encoding no longer exists. Issue: gh-159207
Open Graph Description: Tachyon's binary format currently stores all samples in a single compressed stream. Each record contains its thread and interpreter IDs, timestamp, status, and stack change, so values such as t...
X Description: Tachyon's binary format currently stores all samples in a single compressed stream. Each record contains its thread and interpreter IDs, timestamp, status, and stack change, so values such ...
Opengraph URL: https://github.com/python/cpython/pull/160313
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0b0fcb5e-1f03-b879-0fce-b5534e34a54b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8FC8:246BB9:DDA174:129EF0E:6B064BB4 |
| html-safe-nonce | edceb887c7cd80a526932b0f20885572517327f5cbd2b29eb2382ca3abbf7d57 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkM4OjI0NkJCOTpEREExNzQ6MTI5RUYwRTo2QjA2NEJCNCIsInZpc2l0b3JfaWQiOiIyOTU1OTYxNjEwNjI1NTAyMTMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e4ab5f80a741fd1c930992d6fc196e3d4924b5a48684c2d0d9933590de16fe2e |
| hovercard-subject-tag | pull_request:4972605908 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/160313/files |
| twitter:image | https://avatars.githubusercontent.com/u/80911834?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/80911834?s=400&v=4 |
| og:image:alt | Tachyon's binary format currently stores all samples in a single compressed stream. Each record contains its thread and interpreter IDs, timestamp, status, and stack change, so values such as t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width