Skip to content

Improve RLP encoding/decoding #4956

@Arkenan

Description

@Arkenan

A big part of all reads is encoding and decoding. We should improve our rlp encoding and decoding of trie elements as it seems to be pretty slow and significant (e.g. more than twice the length of db access in some measurements).

The main culprit seems to be allocation.

Some ideas:

  • Some implementations of the RLPEncode trait encode to calculate the length instead of implementing the recursive length function. Implementing that function avoids half of the allocations and memcpys of arrays and structs.
  • We need to check if there are cases where encode_to_vec in loop that can be replaced with encode and recycle the buffer.
  • Sometimes we decode to a vector just so we can iterate. In those cases, we need to test implementing an iterator directly and recycling the buffer.
  • Decoding might be able to predict the size of the content in the case of vectors before decoding, so we might be able to avoid pushing and having intermediate allocs.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions