go-algorand icon indicating copy to clipboard operation
go-algorand copied to clipboard

Perf: txn decoding - reuse encoded txn

Open algorandskiy opened this issue 2 years ago • 0 comments

Re-use encoded txn objects to reduce redundant txn encoding.

Context

When nodes receive gossipped txns, they decode them, perform checks (signature validation etc), and then re-encode them before forwarding them onwards. Currently, nodes re-encode transactions multiple times (calculating txn ID, encoding the txn to forward in gossip, etc), wasting resources.

To boost node performance, we can reduce the number of times they encode txns.

Unknowns:

  1. How much time is spent encoding txns (can check txn profiler)
  2. List of areas we duplicate txn encoding

Raw txn groups and block proposals both contain encoded txns, so we can save re-encoding effort for txns and proposals. Goal: zero allocation for Transaction objects while evaluating it.

Acceptance Criteria

  1. Possibly: measure time spent encoding txn (via txn profiler) to gauge opportunity
  2. Identify areas of duplicate encoding
  3. Implementation
    • For block proposals:
      • Introduce RawPayset []msgp.Raw to Block in order to use it as needed.
      • In Eval iterate RawPayset and decode as needed instead of pre-decoding the Payset.

algorandskiy avatar Sep 13 '22 21:09 algorandskiy