Skip to content

feat(writer): Cached encoding selection policy#922

Open
HuamengJiang wants to merge 1 commit into
facebookincubator:mainfrom
HuamengJiang:export-D109013483
Open

feat(writer): Cached encoding selection policy#922
HuamengJiang wants to merge 1 commit into
facebookincubator:mainfrom
HuamengJiang:export-D109013483

Conversation

@HuamengJiang

Copy link
Copy Markdown

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

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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 29, 2026
@meta-codesync

meta-codesync Bot commented Jun 29, 2026

Copy link
Copy Markdown

@HuamengJiang has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109013483.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant