feat(writer): Cached encoding selection policy#922
Open
HuamengJiang wants to merge 1 commit into
Open
Conversation
Summary: Add `CachedEncodingSelectionPolicy<T>`, an `EncodingSelectionPolicy` subclass that caches the encoding layout from the first encoding of a stream and replays it on subsequent chunks and stripes — skipping the full encoding selection cascade (the expensive `Statistics::create` unique-count pass). Modeled after `ReplayedEncodingSelectionPolicy`: `select()` and `createImpl()` delegate to the factory on first call, then replay the cached layout on subsequent calls. The cache is stored on `WriterStreamContext` (one per stream, persists for the writer lifetime). **Key design decisions:** - Cache only the **data encoding**, stripping any Nullable wrapper — Nimble handles nulls at the outermost layer, so the data encoding is the same regardless of per-stripe nullability. - External `EncodingLayoutTree` replay takes priority over the cache (unchanged from before). - On `IncompatibleEncoding`, falls back to full selection. - Factory stored by value (not reference) to avoid lifetime issues. **Performance impact (P2386350574):** - Local trace replay + cluster A/B (blue_reels): encoding selection = **15.5%** of TableWrite CPU. Caching removes it entirely → **−15.5% write CPU**. - Verifier regression distribution WITH caching (n=1145 PI training tables): mean ratio 1.195 (vs DWRF), 50.7% regress >10%, 23.6% regress >20%. - Big tables (which carry the CPU) benefit most: mean 1.115, only 14% regress >20%. - Tables in the 1.20×–1.42× regression range drop under 1.20× once caching is on (0.845 scaling), converting "offending" tables into rollout candidates. Differential Revision: D109013483
|
@HuamengJiang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109013483. |
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.
Summary:
Add
CachedEncodingSelectionPolicy<T>, anEncodingSelectionPolicysubclass that caches the encoding layout from the first encoding of a stream and replays it on subsequent chunks and stripes — skipping the full encoding selection cascade (the expensiveStatistics::createunique-count pass).Modeled after
ReplayedEncodingSelectionPolicy:select()andcreateImpl()delegate to the factory on first call, then replay the cached layout on subsequent calls. The cache is stored onWriterStreamContext(one per stream, persists for the writer lifetime).Key design decisions:
EncodingLayoutTreereplay takes priority over the cache (unchanged from before).IncompatibleEncoding, falls back to full selection.Performance impact (P2386350574):
Differential Revision: D109013483