Skip to content

Commit 82e76d4

Browse files
committed
Use smallvec to optimize recording multiple event arguments
1 parent 90716e8 commit 82e76d4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

measureme/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ repository = "https://github.com/rust-lang/measureme"
1313
travis-ci = { repository = "rust-lang/measureme" }
1414

1515
[dependencies]
16-
rustc-hash = "1.0.1"
1716
parking_lot = "0.11.0"
17+
rustc-hash = "1.0.1"
18+
smallvec = "1.0"

measureme/src/event_id.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use smallvec::SmallVec;
2+
13
use crate::{Profiler, StringComponent, StringId};
24

35
/// Event IDs are strings conforming to the following grammar:
@@ -80,8 +82,9 @@ impl<'p> EventIdBuilder<'p> {
8082
}
8183

8284
pub fn from_label_and_args(&self, label: StringId, args: &[StringId]) -> EventId {
83-
// The capacity is the number of args + the same number for arg separators + the label.
84-
let mut parts = Vec::with_capacity(args.len() * 2 + 1);
85+
// Store up to 7 components on the stack: 1 label + 3 arguments + 3 argument separators
86+
let mut parts = SmallVec::<[StringComponent; 7]>::with_capacity(1 + args.len() * 2);
87+
8588
parts.push(StringComponent::Ref(label));
8689

8790
for arg in args {

0 commit comments

Comments
 (0)