ipfs / ipfs/go-graphsync

Allocate before loading when responding to queries

Open
#255 2 comments 0 reactions 0 assignees View on GitHub
effort/hours exp/intermediate P2
Dominant language
Go
Stars
103
Forks
41
PR merge metrics
No merged PRs in 30d

Description

In the [query executor](https://github.com/ipfs/go-graphsync/blob/c96b3b2944cacb405594dc15f2333145b2db133a/responsemanager/queryexecutor.go#L87), we seem to _load_ first, then allocate when sending the block. Unfortunately, when processing many parallel queries, we can end up loading a lot of blocks then _blocking_ (waiting to be able to "reserve space" for them. we'd likely use less memory if we just sent the block.

Instead, we should allocate first. That is:

1. Before loading anything, allocate 2-4MiB (maximum block size).
2. Then load.
3. Then reduce the allocation to the _actual_ amount of memory needed.

This means we:

1. Won't go over the allocation limit.
2. If we're blocked on allocating, we won't sit there while holding on to buffers.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.