Most of the note decryption will fail. Currently, if a DecryptNotesResponse contains 100 undecrypted notes, it will create a dense array containing 100 null values, causing unnecessary large memory allocations and large memory writes. It was in fact observed that the arrays from DecryptNotesResponse were one of the top contributors to memory usage during wallet scans.
This commit changes the implementation so that now DecryptNotesResponse would create a sparse array containing no values at all. This means that, when no notes are decrypted (i.e. the most common case), all DecryptNotesResponse objects consume the same amount of memory, regardless of how many accounts are in the wallet, or how many encrypted notes were requested.
This was shown to reduce the peak memory usage of the node process, as well as reduce the number of minor page faults.
Summary
Most of the note decryption will fail. Currently, if a
DecryptNotesResponse
contains 100 undecrypted notes, it will create a dense array containing 100null
values, causing unnecessary large memory allocations and large memory writes. It was in fact observed that the arrays fromDecryptNotesResponse
were one of the top contributors to memory usage during wallet scans.This commit changes the implementation so that now
DecryptNotesResponse
would create a sparse array containing no values at all. This means that, when no notes are decrypted (i.e. the most common case), allDecryptNotesResponse
objects consume the same amount of memory, regardless of how many accounts are in the wallet, or how many encrypted notes were requested.This was shown to reduce the peak memory usage of the node process, as well as reduce the number of minor page faults.
Testing Plan
Documentation
N/A
Breaking Change
N/A