iron-fish / ironfish

A novel cryptocurrency focused on privacy and accessibility.
https://ironfish.network
Mozilla Public License 2.0
962 stars 576 forks source link

Use a sparse array in `DecryptNotesResponse` #5128

Closed andiflabs closed 2 weeks ago

andiflabs commented 2 weeks ago

Summary

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.

Testing Plan

Documentation

N/A

Breaking Change

N/A