Skip to content

Commit

Permalink
Predefine Vector Capacity for LogRecord Attributes (#1908)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Jul 3, 2024
1 parent ad990d6 commit ae6e2ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion opentelemetry-appender-tracing/benches/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| noop_layer_disabled | 12 ns |
| noop_layer_enabled | 25 ns |
| ot_layer_disabled | 19 ns |
| ot_layer_enabled | 371 ns |
| ot_layer_enabled | 305 ns |
*/

use async_trait::async_trait;
Expand Down
7 changes: 6 additions & 1 deletion opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct LoggerProvider {

/// Default logger name if empty string is provided.
const DEFAULT_COMPONENT_NAME: &str = "rust.opentelemetry.io/sdk/logger";
const PREALLOCATED_ATTRIBUTE_CAPACITY: usize = 8;

impl opentelemetry::logs::LoggerProvider for LoggerProvider {
type Logger = Logger;
Expand Down Expand Up @@ -246,7 +247,11 @@ impl opentelemetry::logs::Logger for Logger {
type LogRecord = LogRecord;

fn create_log_record(&self) -> Self::LogRecord {
LogRecord::default()
// Reserve attributes memory for perf optimization. This may change in future.
LogRecord {
attributes: Some(Vec::with_capacity(PREALLOCATED_ATTRIBUTE_CAPACITY)),
..Default::default()
}
}

/// Emit a `LogRecord`.
Expand Down
2 changes: 1 addition & 1 deletion stress/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
OS: Ubuntu 22.04.3 LTS (5.15.146.1-microsoft-standard-WSL2)
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
RAM: 64.0 GB
53 M/sec
69 M/sec
*/

use opentelemetry_appender_tracing::layer;
Expand Down

0 comments on commit ae6e2ff

Please sign in to comment.