Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

aggressively free memory #143

Merged
merged 2 commits into from Jun 19, 2019
Merged

aggressively free memory #143

merged 2 commits into from Jun 19, 2019

Conversation

Stebalien
Copy link
Member

depends on libp2p/go-msgio#15


return pbw.WriteMsg(m.ToProtoV1())
func write(w io.Writer, m *pb.Message) error {
Copy link
Member Author

@Stebalien Stebalien Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should put this in a library somewhere? I'm going to need it in the DHT.

@Stebalien
Copy link
Member Author

This is showing up on the gateways.

This ensures we don't keep large buffers allocated.
@Stebalien Stebalien changed the title [WIP] aggressively free memory aggressively free memory Jun 14, 2019
@Stebalien Stebalien requested a review from Kubuxu June 14, 2019 16:04
@hannahhoward
Copy link
Contributor

@Stebalien is there some context for this?

@Stebalien
Copy link
Member Author

The gateway was locking up a gigabyte in gogo readers: https://github.com/ipfs/go-bitswap/pull/143/files#diff-33bf651b39540d23d5b24eb4a54026cdL181. This patch:

  1. Reads the varint length byte by byte without allocating.
  2. Uses the buffer pool to get a buffer of the correct size for the message.
  3. Reads into this buffer.
  4. Deserializes the message.
  5. Returns the buffer to the pool.

Importantly, it doesn't just hang onto this buffer till the next message comes in.

if err := pb.Unmarshal(msg); err != nil {
return nil, err
}
r.ReleaseMsg(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is your enter key not working?

size := m.Size()
buf := pool.Get(size + binary.MaxVarintLen64)
defer pool.Put(buf)
n := binary.PutUvarint(buf, uint64(size))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what did whitespace ever do to you?

@Stebalien Stebalien merged commit 5628965 into master Jun 19, 2019
@Stebalien Stebalien deleted the fix/free-memory branch June 19, 2019 09:39
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants