Skip to content

timely-util: avoid rebuilding well-formed bucket chains in restore#36897

Merged
antiguru merged 1 commit into
MaterializeInc:mainfrom
antiguru:temporal-restore-fastpath
Jun 4, 2026
Merged

timely-util: avoid rebuilding well-formed bucket chains in restore#36897
antiguru merged 1 commit into
MaterializeInc:mainfrom
antiguru:temporal-restore-fastpath

Conversation

@antiguru
Copy link
Copy Markdown
Member

@antiguru antiguru commented Jun 4, 2026

Motivation

BucketChain::restore allocates a fresh BTreeMap and moves every bucket over on each call, even when the chain is already well-formed — which is the common case, since callers invoke restore after every peel.
In a correction buffer prototype this churn accounted for ~19% of the read-path samples; the production temporal bucketing operators pay the same cost on every frontier advance.

Description

Scan the buckets for well-formedness (each within two bits of its predecessor, starting from an imaginary -2) and return early without touching the map.
The scan is O(buckets) without allocation; the slow path is unchanged.

Verification

Existing temporal unit tests pass.
Measured ~20% improvement on bucketed correction-buffer benchmarks whose read path peels and restores per timestamp.

🤖 Generated with Claude Code

BucketChain::restore allocated a new BTreeMap and moved every bucket on
each call, even when the chain was already well-formed. Callers invoke
restore after every peel, so this cost ~19% of an MV sink correction
buffer prototype's read path. Scan for well-formedness first and return
early.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@antiguru antiguru merged commit d69f688 into MaterializeInc:main Jun 4, 2026
118 checks passed
@antiguru antiguru deleted the temporal-restore-fastpath branch June 4, 2026 10:04
maheshwarip pushed a commit that referenced this pull request Jun 5, 2026
…36897)

### Motivation

`BucketChain::restore` allocates a fresh `BTreeMap` and moves every
bucket over on each call, even when the chain is already well-formed —
which is the common case, since callers invoke `restore` after every
`peel`.
In a correction buffer prototype this churn accounted for ~19% of the
read-path samples; the production temporal bucketing operators pay the
same cost on every frontier advance.

### Description

Scan the buckets for well-formedness (each within two bits of its
predecessor, starting from an imaginary -2) and return early without
touching the map.
The scan is O(buckets) without allocation; the slow path is unchanged.

### Verification

Existing `temporal` unit tests pass.
Measured ~20% improvement on bucketed correction-buffer benchmarks whose
read path peels and restores per timestamp.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants