From: Matt Joiner Date: Thu, 9 Sep 2021 12:16:24 +0000 (+1000) Subject: Make readahead algorithm linear X-Git-Tag: v1.32.0~88 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=58483ae3990f2eefa9e570db2d74ff02637686ec;p=btrtrc.git Make readahead algorithm linear --- diff --git a/reader.go b/reader.go index 745409f4..78a2ff00 100644 --- a/reader.go +++ b/reader.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "math" "sync" "github.com/anacrolix/log" @@ -292,7 +291,7 @@ func (r *reader) log(m log.Msg) { r.t.logger.Log(m.Skip(1)) } -// Implementation inspired from an arbitrary comment I found on HN. -func (r *reader) sqrtReadahead() int64 { - return int64(math.Sqrt(float64(r.pos - r.contiguousReadStartPos))) +// Implementation inspired by https://news.ycombinator.com/item?id=27019613. +func (r *reader) defaultReadaheadFunc() int64 { + return r.pos - r.contiguousReadStartPos } diff --git a/t.go b/t.go index 8da39883..ebb32883 100644 --- a/t.go +++ b/t.go @@ -42,7 +42,7 @@ func (t *Torrent) newReader(offset, length int64) Reader { offset: offset, length: length, } - r.readaheadFunc = r.sqrtReadahead + r.readaheadFunc = r.defaultReadaheadFunc t.addReader(&r) return &r }