-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Reduce memory usage with a Buffer pool #1337
Comments
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. |
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. |
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.
The text was updated successfully, but these errors were encountered: