Repository navigation
Conversation
Measures the current proto.Size(ToWire(...)) path so the follow-up allocation-free implementation can be compared against it. Signed-off-by: Yasuhiro Matsumoto <[email protected]>
9e35cf1 to
5cf4253
Compare
Add FileInfo.WireSize that walks the fields directly and sums protobuf tag and varint lengths without allocating an intermediate wire message. A cross-check test asserts it matches proto.Size(ToWire(...)) over representative FileInfo shapes. Switch the hot callers (FileInfoBatch.Append and encryptionTrailerSize) to the new method. Signed-off-by: Yasuhiro Matsumoto <[email protected]>
5cf4253 to
8901f09
Compare
|
Hmm, I'm skeptical. Not enamoured with the idea of maintaining a separate copy of protobuf encoding rules, and easy for this to drift out of sync as the types in question evolve. |
|
An alternative might be to just drop the wire size threshold - I don't think it carries its weight anymore: For many usecases of this batch it's largely irrelevant aka those writing to DB not to a connection. And if we want to keep the max. wire size per batch on the connection, we can check and split the batch at the protocol layer after we converted to wire format and thus get the size "for free" with |
|
For the batching, I think it makes sense to keep the message size reasonable, at least to the point that if we've built up a reasonably sized batch there is no advantage to delaying further and we should just send it, even if it's only two (large) files. But this doesn't require any kind of precise size metric; we could equally well say that a batch is (e.g.) 250 files or 10000 blocks, and that'll cover the same purpose with a trivial int counter. (For the encryption trailer we do need the precise size I think, but this happens just once in relation to a file operation that will get fsync()ed etc so I think the performance aspect is irrelevant more or less.) |
We used a size computation to generate reasonably sized batches, but the ProtoSize call is fairly expensive as it requires a conversion to a wire type etc. We don't need that much precision. Instead, just limit to 1000 files or 5000 blocks, which is likely approximately that much data anyway. Closes #10707 Signed-off-by: Jakob Borg <[email protected]>
Purpose
FileInfoBatch.AppendandencryptionTrailerSizeonly need the serialized size of aFileInfo, but usedproto.Size(f.ToWire(...)), which allocates a full wire message just to measure it. On the index batching and encrypted puller paths this is visible in allocation profiles.This PR adds
FileInfo.WireSize(withInternalFields bool) intthat walks fields directly and sums protobuf tag/varint/length-prefix sizes without allocating an intermediate message, and switches both hot callers to it.The change is split into two commits so the benchmark can be run on each to compare:
lib/protocol: add benchmark for FileInfo wire sizelib/protocol: avoid protobuf allocations when sizing FileInfoTesting
TestFileInfoWireSizeMatchesProtoSizecross-checksWireSizeagainstproto.Size(ToWire(...))over representativeFileInfoshapes (empty, full file with blocks/xattrs, symlink with internal flags), with and without internal fields.The two commits on this branch are arranged so that
BenchmarkFileInfoSizemeasures the old path at the first commit and the new path at the second. To reproduce:Result on AMD Ryzen 7 7735HS (8 runs):
Documentation
Not applicable — internal helper, no user-visible or wire-protocol change.
Authorship
Your name and email will be added automatically to the AUTHORS file based on the commit metadata.