Commit cd315c81 authored by Steven Allen's avatar Steven Allen

always prefetch at least 5 blocks ahead

This should reduce stuttering when streaming.

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent f191b873
...@@ -68,8 +68,7 @@ func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv ...@@ -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 { ...@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment