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

Reduce memory usage with a Buffer pool #1337

Closed
daviddias opened this issue May 5, 2018 · 2 comments
Closed

Reduce memory usage with a Buffer pool #1337

daviddias opened this issue May 5, 2018 · 2 comments
Assignees

Comments

@daviddias
Copy link
Member

Coming out from a productive chat with @mafintosh about buffer allocation, garbage collection and overall main perf sources of problems in JavaScript still today. Also got introduced to https://github.com/mafintosh/buffer-reuse-pool.

We can potentially (pretty much 100% certain) reduce the memory usage of js-ipfs and js-libp2p by adopting a similar strategy and also use it to cap memory usage.

@daviddias daviddias added the status/ready Ready to be worked label May 30, 2018
@mcollina
Copy link

image

The above diagram shows how this type of Buffer pooling system could work. Note that it assumes that the Network and Store layers could avoid buffer reallocation themselves (which is currently not true in Node.js, and it assumes relying on native addons).

After 3 months digging in js-ipfs codebase, I do not think this is feasible to implement given the current guiding principles of this project. Ipfs and libp2p are multi-protocol and designed with composability in mind. They are not designed to achieve maximum performance over a single protocol, but rather to support a wide range of network protocols and use cases. Implementing this feature would require a massive rearchitecting of the whole of js-ipfs and its dependencies.

As mentioned in #1788 and in a lot of other places, I think js-ipfs should adopt a high-level object to represent a "series of buffers" so that they could be easily moved around without having to allocate a new one at every single step. This will reduce the amount of new allocations to the minimum during the processing of a chunk. I think this change is incremental and less disruptive than reusing buffers.

@whizzzkid
Copy link

js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide.

Please feel to reopen with any comments before 2023-06-05. We will do a final pass on reopened issues afterward (see #4336).

This might already be resolved in Helia, if not please feel free to create an issue there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants