mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
always prefetch at least 5 blocks ahead
This should reduce stuttering when streaming. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
@ -68,8 +68,7 @@ func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv
|
|||||||
|
|
||||||
const preloadSize = 10
|
const preloadSize = 10
|
||||||
|
|
||||||
func (dr *PBDagReader) preloadNextNodes(ctx context.Context) {
|
func (dr *PBDagReader) preload(ctx context.Context, beg int) {
|
||||||
beg := dr.linkPosition
|
|
||||||
end := beg + preloadSize
|
end := beg + preloadSize
|
||||||
if end >= len(dr.links) {
|
if end >= len(dr.links) {
|
||||||
end = len(dr.links)
|
end = len(dr.links)
|
||||||
@ -90,8 +89,13 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
|
|||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
if dr.promises[dr.linkPosition] == nil {
|
// If we drop to <= preloadSize/2 preloading nodes, preload the next 10.
|
||||||
dr.preloadNextNodes(ctx)
|
for i := dr.linkPosition; i < dr.linkPosition+preloadSize/2 && i < len(dr.promises); i++ {
|
||||||
|
// TODO: check if canceled.
|
||||||
|
if dr.promises[i] == nil {
|
||||||
|
dr.preload(ctx, i)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nxt, err := dr.promises[dr.linkPosition].Get(ctx)
|
nxt, err := dr.promises[dr.linkPosition].Get(ctx)
|
||||||
|
Reference in New Issue
Block a user