Skip to content

Commit

Permalink
fix: allow GC to run
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Aug 15, 2023
1 parent a771b3f commit 132d946
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/blockstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class BatchingR2Blockstore extends R2Blockstore {
}
})())

let resolvedBlocks = 0
while (true) {
try {
const blockHeader = await readBlockHead(bytesReader)
Expand All @@ -139,6 +140,7 @@ export class BatchingR2Blockstore extends R2Blockstore {
const key = mhToKey(blockHeader.cid.multihash.bytes)
const blocks = pendingBlocks.get(key)
if (blocks) {
resolvedBlocks++
// console.log(`got wanted block for ${blockHeader.cid}`)
const block = {
cid: blockHeader.cid,
Expand Down Expand Up @@ -185,6 +187,11 @@ export class BatchingR2Blockstore extends R2Blockstore {
// bytesReader throws for bad data _before_ the end then we need to
// cancel the reader - we don't need the rest.
reader.cancel()

// Yield to allow GC to run - DO NOT REMOVE!
await new Promise(resolve => setTimeout(resolve))

console.log(`batcher efficiency ${resolvedBlocks}:1`)
}

// resolve `undefined` for any remaining blocks
Expand Down

0 comments on commit 132d946

Please sign in to comment.