Skip to content

Conversation

@mattklein123
Copy link
Contributor

For logs with many fields, the fact that fb is padded and doesn't use varint encoding leads to substantial overhead. This removes that overhead. As part of this change I went a bit over the top and also implemented a custom encoder for the Log proto which allows for zero copy into the ring buffer. This is better than the previous fb implementation which encoded and then did a memcpy into the buffer.

For logs with many fields, the fact that fb is padded and doesn't
use varint encoding leads to substantial overhead. This removes
that overhead. As part of this change I went a bit over the top
and also implemented a custom encoder for the Log proto which
allows for zero copy into the ring buffer. This is better than the
previous fb implementation which encoded and then did a memcpy into
the buffer.

Signed-off-by: Matt Klein <[email protected]>
// Helpers for doing raw casts where we are sure the value fits and don't want to pay for
// checks and avoid clippy lints.
pub trait LossyIntToU32 {
fn to_u32(self) -> u32;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be called to_u32_lossy just to make it obvious?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

) -> u64 {
let mut my_size = 0;

my_size += ::protobuf::rt::uint64_size(1, occurred_at.unix_timestamp_nanos().to_u64() / 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does nanos / 1000 come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's microseconds since epoch. I will add more comments everywhere.

)
}

pub fn serialize_proto_to_stream_inner(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously this means that we need to maintain this as more fields are added - any way to have a test fail in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah can do.

os.write_uint32(2, log_level)?;
}

Self::serialize_proto_data(3, message, os)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed you checked but there's no constants available in the generated proto with the field IDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so but will double check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants