Skip to content

Relocate Delta's selection policy into cost-model priors; plumb the model through the builders#8700

Closed
connortsui20 wants to merge 5 commits into
cost-model-r3-lower-boundfrom
cost-model-r5-builders
Closed

Relocate Delta's selection policy into cost-model priors; plumb the model through the builders#8700
connortsui20 wants to merge 5 commits into
cost-model-r3-lower-boundfrom
cost-model-r5-builders

Conversation

@connortsui20

@connortsui20 connortsui20 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Tracking Issue: #8701

Rationale for this change

Delta's selection policy — the 0.95 "delta tax" and the 1.25 minimum-win floor — is an execution-speed judgment expressed as ratio fudge factors inside the scheme. This PR moves that policy onto the cost model as data (a per-scheme prior), and makes the model configurable end to end: through BtrBlocksCompressorBuilder and, via the file writer's strategy, into both the data and stats compressors (#7697).

Stacked on #8699. Behavior-preserving by construction: the model applies the identical arithmetic in the identical order, so scores are bit-identical — zero golden snapshot churn, including the variant where Delta wins corpus entries.

What changes are included in this PR?

  • SizeCost gains per-scheme priors (SchemePrior { multiplier, min_ratio }); DeltaScheme reports raw ratios, and its prior is registered on the btrblocks default cost model, where the policy is documented as policy, not measurement.
  • BtrBlocksCompressorBuilder::with_cost_model; a configured model rides through WriteStrategyBuilder into both writer compressors. Liveness tests prove the plumbing drives selection (an inverted model flips the winner, and writes a strictly larger file).

What APIs are changed? Are there any user-facing changes?

Additive: SchemePrior, SizeCost::with_scheme_prior, BtrBlocksCompressorBuilder::with_cost_model, and a cost re-export from vortex-btrblocks. Deprecated: DeltaScheme::new(min_ratio) — the floor belongs on the model; the constructor keeps working and can only tighten policy. Embedders assembling CascadingCompressor directly with DeltaScheme should attach a prior-bearing model (as the builder does) to retain the handicap. Default compressor output is byte-identical.

@connortsui20 connortsui20 added the changelog/deprecation A change that introduces a series of API deprecations label Jul 9, 2026 — with Claude
@connortsui20 connortsui20 marked this pull request as draft July 9, 2026 15:42
@connortsui20 connortsui20 force-pushed the cost-model-r5-builders branch from cfa1afe to a380163 Compare July 9, 2026 17:17
@connortsui20 connortsui20 force-pushed the cost-model-r3-lower-bound branch 2 times, most recently from f4617b8 to d7a3b3a Compare July 10, 2026 09:18
@connortsui20 connortsui20 force-pushed the cost-model-r5-builders branch from a380163 to b81955f Compare July 10, 2026 09:18
@codspeed-hq

codspeed-hq Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 2 improved benchmarks
❌ 3 regressed benchmarks
✅ 1616 untouched benchmarks
🆕 39 new benchmarks
⏩ 47 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation chunked_varbinview_into_canonical[(100, 100)] 271.6 µs 327.8 µs -17.13%
Simulation chunked_varbinview_opt_canonical_into[(100, 100)] 305.3 µs 367.6 µs -16.96%
Simulation encode_primitives[i64, (1000, 512)] 117.5 µs 137.6 µs -14.6%
Simulation chunked_bool_canonical_into[(1000, 10)] 16.4 µs 14.6 µs +12.36%
Simulation true_count_vortex_buffer[128] 638.3 ns 580 ns +10.06%
🆕 Simulation ilike_contains N/A 782.5 µs N/A
🆕 Simulation like_contains N/A 154.5 µs N/A
🆕 Simulation like_exact N/A 43.9 µs N/A
🆕 Simulation like_per_row_patterns N/A 168.7 µs N/A
🆕 Simulation like_prefix N/A 50.9 µs N/A
🆕 Simulation like_regex N/A 623 µs N/A
🆕 Simulation like_suffix N/A 64.9 µs N/A
🆕 Simulation cached_indices_i128[0.01] N/A 29 µs N/A
🆕 Simulation cached_indices_i128[0.1] N/A 82.1 µs N/A
🆕 Simulation cached_indices_i32[0.01] N/A 22.5 µs N/A
🆕 Simulation cached_indices_i32[0.1] N/A 55.9 µs N/A
🆕 Simulation patterns_i128[Contiguous] N/A 234.8 µs N/A
🆕 Simulation patterns_i128[Random] N/A 290.4 µs N/A
🆕 Simulation patterns_i128[Runs] N/A 244.8 µs N/A
🆕 Simulation random_i128[0.01] N/A 29.2 µs N/A
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cost-model-r5-builders (a89ad4c) with cost-model-r3-lower-bound (d7a3b3a)2

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on cost-model-r3-lower-bound (02309ed) during the generation of this report, so afb6425 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

connortsui20 and others added 5 commits July 14, 2026 15:39
SizeCost gains a prior table keyed by SchemeId: SchemePrior carries a
multiplier applied to the scheme's raw ratio signal (values below 1.0
demand the scheme win by a margin) and a floor the effective ratio must
strictly exceed. Priors apply in candidate pricing, so the model is the
single place a handicapped scheme's effective ratio is computed.
Schemes without an entry are priced off their raw ratio exactly as
before, and SizeCost::default() registers no priors, so behavior is
unchanged.

Priors are policy, not measurement: this is the home for judgments like
the Delta 'tax', which moves here from the scheme in the next commit.
SizeCost gives up Copy for the table; it remains Clone + Default.

Unit tests pin the prior arithmetic bit-for-bit against the historical
scheme-side expression (raw * multiplier, floor comparison included).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aqw9S8Q1wSpNjaRhdFQ1uf
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
DeltaScheme now reports its raw estimated ratio (full_width /
delta_bits); the 'delta tax' multiplier (0.95) and minimum-win floor
(1.25) are registered as Delta's SchemePrior on the btrblocks default
cost model, which BtrBlocksCompressorBuilder::build() now attaches. The
model applies the identical arithmetic in the identical order (raw *
multiplier, floor comparison), so scores and selections are
bit-identical: the golden suite — including the unstable variant where
Delta wins int_monotone_jitter — shows zero snapshot churn.

The ALL_SCHEMES 'prefer above delta' registration comment moves to
default_cost_model, where the policy now lives and is documented as
policy, not measurement.

DeltaScheme::new(min_ratio) is deprecated: the floor belongs on the
model (SizeCost::with_scheme_prior). The constructor keeps working —
a configured floor still gates via the historical post-penalty
comparison — but it can only tighten policy, since the model's prior
floor also applies. Note for embedders: assembling CascadingCompressor
directly with DeltaScheme now requires attaching a prior-bearing model
(as the builder does) to retain the handicap; the scheme alone no
longer penalizes itself.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aqw9S8Q1wSpNjaRhdFQ1uf
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
The builder carries an Arc<dyn CostModel> (defaulting to the btrblocks
default model: SizeCost with Delta's prior) and attaches it at build().
vortex_compressor::cost is re-exported from vortex_btrblocks so
embedders can name CostModel, Cost, SizeCost, and SchemePrior without a
direct vortex-compressor dependency.

An end-to-end test proves the plumbing is live: under the default model
the higher-ratio scheme wins; under an injected inverted model the
lower-ratio scheme wins.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aqw9S8Q1wSpNjaRhdFQ1uf
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
CompressorConfig::BtrBlocks holds the whole BtrBlocksCompressorBuilder,
so a cost model configured via with_cost_model now rides through
WriteStrategyBuilder::build() into both the data compressor (which
clones the builder and excludes IntDictScheme) and the stats/values
compressor, with no strategy code changes needed; this change documents
that on with_btrblocks_builder and proves it with an integration test:
on the same highly compressible column, a strategy carrying an inverted
model writes a strictly larger file than the default strategy.

No Python surface is added yet, deviating deliberately from the
NEXT-STEPS strawman ('Python preset stubs'): a Python surface with only
the default model behind it is confusable dead API; it lands with the
first real preset in C1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aqw9S8Q1wSpNjaRhdFQ1uf
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
DeltaScheme's public docs linked to the crate-private builder module;
describe the default cost model in prose instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Aqw9S8Q1wSpNjaRhdFQ1uf
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@connortsui20 connortsui20 force-pushed the cost-model-r3-lower-bound branch from d7a3b3a to 02309ed Compare July 14, 2026 15:54
@connortsui20 connortsui20 force-pushed the cost-model-r5-builders branch from b81955f to a89ad4c Compare July 14, 2026 15:54
@connortsui20 connortsui20 deleted the cost-model-r5-builders branch July 15, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/deprecation A change that introduces a series of API deprecations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant