Skip to content

Commit

Permalink
target readahead to max 5% instead of 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Sep 11, 2024
1 parent cb852e4 commit d272937
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/prefetcher.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// should move to hypercore itself

const MAX_READAHEAD_TARGET = 0.05 // aim to buffer 5% always

module.exports = class Prefetcher {
constructor (core, { max = 64, start = 0, end = core.length, linear = true } = {}) {
this.core = core
this.max = max
this.range = null
this.startBound = start
this.endBound = end
this.maxReadAhead = Math.max(max * 2, Math.floor((end - start) * MAX_READAHEAD_TARGET))

this.start = start
this.end = start
Expand Down Expand Up @@ -48,6 +51,7 @@ module.exports = class Prefetcher {
this.missing++
}

if (end > this.start + this.maxReadAhead) end = this.start + this.maxReadAhead
if (end >= this.endBound) end = this.endBound

this.end = end
Expand Down

0 comments on commit d272937

Please sign in to comment.