Skip to content

Commit

Permalink
Move to SmallRng from ThreadRng
Browse files Browse the repository at this point in the history
SmallRng provides 0-6% improvement in Traces.

Relates open-telemetry#808
  • Loading branch information
hdost committed Oct 18, 2023
1 parent 03b94b3 commit bb71c6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion opentelemetry-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ futures-util = { version = "0.3.17", default-features = false, features = ["std"
once_cell = "1.10"
ordered-float = "4.0"
percent-encoding = { version = "2.0", optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng","small_rng"], optional = true }
glob = {version = "0.3.1", optional =true}
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
serde_json = { version = "1", optional = true }
Expand Down Expand Up @@ -68,6 +68,7 @@ harness = false
[[bench]]
name = "trace"
harness = false
required-features = ["testing"]

[[bench]]
name = "batch_span_processor"
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/trace/id_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pub(super) mod aws;

use opentelemetry::trace::{SpanId, TraceId};
use rand::{rngs, Rng};
use rand::{rngs, Rng, SeedableRng};
use std::cell::RefCell;
use std::fmt;

Expand Down Expand Up @@ -35,5 +35,5 @@ impl IdGenerator for RandomIdGenerator {

thread_local! {
/// Store random number generator for each thread
static CURRENT_RNG: RefCell<rngs::ThreadRng> = RefCell::new(rngs::ThreadRng::default());
static CURRENT_RNG: RefCell<rngs::SmallRng> = RefCell::new(rngs::SmallRng::from_entropy());
}

0 comments on commit bb71c6c

Please sign in to comment.