Skip to content

Commit d272937

Browse files
committed
target readahead to max 5% instead of 100%
1 parent cb852e4 commit d272937

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/prefetcher.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// should move to hypercore itself
22

3+
const MAX_READAHEAD_TARGET = 0.05 // aim to buffer 5% always
4+
35
module.exports = class Prefetcher {
46
constructor (core, { max = 64, start = 0, end = core.length, linear = true } = {}) {
57
this.core = core
68
this.max = max
79
this.range = null
810
this.startBound = start
911
this.endBound = end
12+
this.maxReadAhead = Math.max(max * 2, Math.floor((end - start) * MAX_READAHEAD_TARGET))
1013

1114
this.start = start
1215
this.end = start
@@ -48,6 +51,7 @@ module.exports = class Prefetcher {
4851
this.missing++
4952
}
5053

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

5357
this.end = end

0 commit comments

Comments
 (0)