Skip to content
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

Predefine Vector Capacity for LogRecord Attributes #1908

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | 270 ns |
Copy link
Member

Choose a reason for hiding this comment

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

❤️ this! Could you update stress tests too?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated stress. The benchmark shows improvement from 391 ns -> 305 ns. Updated that too.

*/

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
Loading