open-telemetry / opentelemetry-rust

The Rust OpenTelemetry implementation
https://opentelemetry.io
Apache License 2.0
1.71k stars 386 forks source link

LogRecord Attributes - preallocate attributes vec? #1896

Closed cijothomas closed 21 hours ago

cijothomas commented 6 days ago

image Since we don't pre-allocate, the vec starts with size 1, and often requires re-allocating. Would we start with a default size of, say 5? (don't ask me why 5, just a magic number!)

Opening an issue to track this improvement. The change can improve current throughput, benchmark by 10-20% (as they all need ~5 attributes.)

lalitb commented 6 days ago

Thanks, let's track this potential improvement with benchmark of both memory and throughput while handling this.

cijothomas commented 2 days ago

From 7/2 SIG meeting: Start with default = 8. In future, we can make it configurable, if we chose to and there is demand.

lalitb commented 1 day ago

I think we discussed it earlier - If we plan to start with default size, we can also evaluate using smallvec, to allocate this initial capacity on stack. tokio-tracing is doing something similar for the metrics attributes.