-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize the bytes encoding at node #606
Conversation
buf := bytes.NewBuffer(make([]byte, 0)) | ||
totalSize := 0 | ||
for _, chunk := range chunks { | ||
totalSize += len(chunk) + 8 // Add size of uint64 for length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for every blob, all chunks have uniform length, and this is dictated by kzg encoder. For a blob of 128kiB, based on current stake distribution, it will create 4096 chunks. Suppose coding ratio is 8, then every chunk has size 2^17*8/4096=256Byte, if we add 8 bytes to store the length, we are wasting 3% storage. It becomes less of a problem if blob length is larger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, uint32 is sufficient in most case, because it is going to take long time to reach 4Gb chunks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of this, but changing encoding should be handled in a compatible way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr itself looks good to me
Why are these changes needed?
When workload is high, the bytes encoding can be quite large (about 50% of actual DB write latency).
This PR avoids unnecessary memory movement when dealing with multiple chunks (on large operators). In addition, this re-implements the encoding in more efficient way.
Benchmark result shows near 4x improvement of performance (the BenchmarkEncodeChunksOld is before this PR, BenchmarkEncodeChunks is this PR):
PASS
ok github.com/Layr-Labs/eigenda/node 10.581s
Checks