We can improve the performance of Push and ComputeRoot methods by implementing buffer reuse strategies for hash computations (HashLeaf and HashNode methods).
While this optimisation won't be suitable for all use cases, it can provide performance improvements in ProcessProposal.
Proposed Optimisations:
In-place root computation
Introduce a new method (e.g., RootInPlace, ConsumeRoot, or FastConsumeRoot) that:
- Reuses the
leafHashes buffer when computing intermediate node hashes during root calculation
- Modifies internal buffers in place rather than allocating new ones
- Clearly indicates through naming that the NMT instance becomes unusable after the operation
NMT instance pooling
Implement object pooling for ProcessProposal:
- Maintain a pool of pre-allocated NMT instances
- Allocate memory once during the first block processing
- Reuse NMT instances from the pool for subsequent operations, reducing allocation overhead
We can improve the performance of
PushandComputeRootmethods by implementing buffer reuse strategies for hash computations (HashLeafandHashNodemethods).While this optimisation won't be suitable for all use cases, it can provide performance improvements in
ProcessProposal.Proposed Optimisations:
In-place root computation
Introduce a new method (e.g.,
RootInPlace,ConsumeRoot, orFastConsumeRoot) that:leafHashesbuffer when computing intermediate node hashes during root calculationNMT instance pooling
Implement object pooling for
ProcessProposal: