Skip to content

Share decoded blocks between callers inflating the same node - #105

Open
mafintosh wants to merge 2 commits into
mainfrom
inflation
Open

mafintosh wants to merge 2 commits into
mainfrom
inflation

Conversation

@mafintosh

Copy link
Copy Markdown
Contributor

Every caller runs the inflation IO under its own config, so timeout, wait and cancellation are per caller and hypercore dedups the fetches. Decoded blocks land in slots on ptr.inflating shared by all callers, so the first to wake decodes and a late caller only fetches what is still missing.

@mafintosh
mafintosh requested a review from a team October 15, 2026 00:06
Every caller runs the inflation IO under its own config, so timeout, wait
and cancellation are per caller and hypercore dedups the fetches. Decoded
blocks land in slots on ptr.inflating shared by all callers, so the first
to wake decodes and a late caller only fetches what is still missing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@caolan-tether

Copy link
Copy Markdown

This risks parallel walks of the tree to inflate the node but most the actual work is shared so the cost should be minimal. It also respects the 'wait' option that is difficult to handle with a simple lock as proposed in #94. Seems like a good idea to me.

@mafintosh
mafintosh requested a review from a team October 20, 2026 12:05
@caolan-tether

Copy link
Copy Markdown

I ran this through hyperbee-benchmarks with no noticeable change in performance.

@caolan-tether

Copy link
Copy Markdown

I also ran this with a large database and tested memory usage. It is comparable to main (while fixing some edge cases). I tested pre-shared-inflate code too and observed the difference in memory usage. It seems to continue to address the OOM case the original inflate sharing code was written for.

@caolan-tether caolan-tether left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I believe @lejeunerenard also wants to take a look before merging.

mafintosh added a commit that referenced this pull request Oct 21, 2026
Ports the two context APIs from #105 so the invalidation check in
getBlock resolves the owning context synchronously.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
mafintosh added a commit that referenced this pull request Oct 21, 2026
* Add invalidation pointer to blocks

Block-1 gains an optional invalidation uint. Every decode path returns it
(0 for block-0 and bee1 compat blocks), and the writer carries the last
loaded value forward into new blocks.

The core context tracks the pointer it loaded its table with and reloads
the table when a block carries a newer one, in addition to the existing
reload when a referenced core is missing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Split getBlock into getBlockBuffer and add getLoadedContext

Ports the two context APIs from #105 so the invalidation check in
getBlock resolves the owning context synchronously.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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