Skip to content

Optimise NMT Performance Through Buffer Reuse #297

@mcrakhman

Description

@mcrakhman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions