Memory leaks in long-running processes #5981
Labels
P2 - Medium
Important but not urgent. Enhances functionality and value, scheduled after higher priorities.
Performance
Optimizations to boost SDK speed, reduce latency, and enhance memory efficiency.
It's known that using the Polkadot.js API library in long-running processes, such as on a Node.js backend, results in increasing memory consumption until the process crashes due to memory leaks.
Below is a summary of the major memory leaks and how to fix them:
Well-known memory leak in
@polkadot/rpc-core
storage cache:Memory leak in ApiPromise timers #5674 (comment)
Patch: Link
Function memoization used across the library via the
memo
utility:api/packages/rpc-core/src/util/memo.ts
Line 20 in 87bee8a
Further investigation is needed to identify the leaky usage. As a quick fix, patch the memoize function in
@polkadot/util
:Patch: Link
LRU cache in
@polkadot/rpc-provider
:The custom LRU cache implementation is not being properly evicted. Supposedly fixed in Fix LRUCache memory leak. #4520, but it still leaks in long-running processes. As a workaround, disable the cache:
Patch: Link
Applying these patches will significantly reduce memory consumption and help maintain a stable footprint for your Node.js long-running processes using Polkadot.js.
We would like to investigate these issues in more detail, but due to other priorities, we currently don't have the time.
The text was updated successfully, but these errors were encountered: