GitBulletin

Repository: farcasterxyz/hub-monorepo

BREAKTHROUGH IN MEMORY MANAGEMENT: MERKLETRIE DEFIES LEAKS!

2023-02-02 16:19:15 UTC

Revolutionary fix slashes memory usage from 1341 bytes to a mere 44 bytes per entry, propelling efficiency to new heights!

Commit Details:

fix: memory leak in MerkleTrie (#502) Node's Buffer uses pooled memory chunk of 8KB by default. The memory pool won't be freed until all Buffers that reference the pool is freed. TrieNode creates a bunch of temporary Buffers during MerkleTrie.insert. And it has a long-lived Buffer that stores the key of an entry. As a result, the short-lived Buffers creates a lot of holes in memory pools, but pools can’t be freed because part of them are referenced by long-lived TrieNodes. The fix is to create new Uint8Array instances (which doesn't use shared memory pool) when TrieNodes store the keys. This change also improves the Buffer usage during TrieNode hash calculation. With this change, average ArrayBuffer usage is down from 1341 bytes to 44 bytes per entry.

Search Similar