Skip to content

Commit f541477

Browse files
Use inplace normalization and add benchmark
1 parent 7f9ec03 commit f541477

File tree

8 files changed

+498
-374
lines changed

8 files changed

+498
-374
lines changed

tools/docker/Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ COPY "data-pipeline/Cargo.toml" "data-pipeline/"
106106
COPY "data-pipeline-ffi/Cargo.toml" "data-pipeline-ffi/"
107107
COPY "bin_tests/Cargo.toml" "bin_tests/"
108108
RUN find -name "Cargo.toml" | sed -e s#Cargo.toml#src/lib.rs#g | xargs -n 1 sh -c 'mkdir -p $(dirname $1); touch $1; echo $1' create_stubs
109-
RUN echo profiling/benches/main.rs profiling/benches/interning_strings.rs trace-obfuscation/benches/trace_obfuscation.rs tools/src/bin/dedup_headers.rs tools/sidecar_mockgen/src/bin/sidecar_mockgen.rs ddtelemetry/examples/tm-worker-test.rs ipc/tarpc/tarpc/examples/compression.rs ipc/tarpc/tarpc/examples/custom_transport.rs ipc/tarpc/tarpc/examples/pubsub.rs ipc/tarpc/tarpc/examples/readme.rs ipc/tarpc/tarpc/examples/tracing.rs ipc/tarpc/tarpc/tests/compile_fail.rs ipc/tarpc/tarpc/tests/dataservice.rs ipc/tarpc/tarpc/tests/service_functional.rs bin_tests/src/bin/crashtracker_bin_test.rs bin_tests/src/bin/test_the_tests.rs | xargs -n 1 sh -c 'mkdir -p $(dirname $1); touch $1; echo $1' create_stubs
109+
RUN echo trace-normalization/benches/normalization_utils.rs profiling/benches/main.rs profiling/benches/interning_strings.rs trace-obfuscation/benches/trace_obfuscation.rs tools/src/bin/dedup_headers.rs tools/sidecar_mockgen/src/bin/sidecar_mockgen.rs ddtelemetry/examples/tm-worker-test.rs ipc/benches/ipc.rs ipc/tarpc/tarpc/examples/compression.rs ipc/tarpc/tarpc/examples/custom_transport.rs ipc/tarpc/tarpc/examples/pubsub.rs ipc/tarpc/tarpc/examples/readme.rs ipc/tarpc/tarpc/examples/tracing.rs ipc/tarpc/tarpc/tests/compile_fail.rs ipc/tarpc/tarpc/tests/dataservice.rs ipc/tarpc/tarpc/tests/service_functional.rs bin_tests/src/bin/crashtracker_bin_test.rs bin_tests/src/bin/test_the_tests.rs | xargs -n 1 sh -c 'mkdir -p $(dirname $1); touch $1; echo $1' create_stubs
110110

111111
# cache dependencies
112112
RUN cargo fetch --locked

trace-normalization/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ datadog-trace-protobuf = { path = "../trace-protobuf" }
1414
[dev-dependencies]
1515
rand = "0.8.5"
1616
duplicate = "0.4.1"
17+
criterion = "0.5"
18+
19+
[[bench]]
20+
name = "normalization_utils"
21+
harness = false
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
5+
6+
fn normalize_service_bench(c: &mut Criterion) {
7+
let mut group = c.benchmark_group("normalization");
8+
let cases = &[
9+
("#test_starting_hash", "test_starting_hash"),
10+
("TestCAPSandSuch", "testcapsandsuch"),
11+
(
12+
"Test Conversion Of Weird !@#$%^&**() Characters",
13+
"test_conversion_of_weird_characters",
14+
),
15+
("$#weird_starting", "weird_starting"),
16+
("allowed:c0l0ns", "allowed:c0l0ns"),
17+
("1love", "love"),
18+
("ünicöde", "ünicöde"),
19+
("ünicöde:metäl", "ünicöde:metäl"),
20+
("Data🐨dog🐶 繋がっ⛰てて", "data_dog_繋がっ_てて"),
21+
(" spaces ", "spaces"),
22+
(" #hashtag!@#spaces #__<># ", "hashtag_spaces"),
23+
(":testing", ":testing"),
24+
("_foo", "foo"),
25+
(":::test", ":::test"),
26+
("contiguous_____underscores", "contiguous_underscores"),
27+
("foo_", "foo"),
28+
(
29+
"\u{017F}odd_\u{017F}case\u{017F}",
30+
"\u{017F}odd_\u{017F}case\u{017F}",
31+
), // edge-case
32+
("", ""),
33+
(" ", ""),
34+
("ok", "ok"),
35+
("™Ö™Ö™™Ö™", "ö_ö_ö"),
36+
("AlsO:ök", "also:ök"),
37+
(":still_ok", ":still_ok"),
38+
("___trim", "trim"),
39+
("12.:trim@", ":trim"),
40+
("12.:trim@@", ":trim"),
41+
("fun:ky__tag/1", "fun:ky_tag/1"),
42+
("fun:ky@tag/2", "fun:ky_tag/2"),
43+
("fun:ky@@@tag/3", "fun:ky_tag/3"),
44+
("tag:1/2.3", "tag:1/2.3"),
45+
("---fun:k####y_ta@#g/1_@@#", "fun:k_y_ta_g/1"),
46+
("AlsO:œ#@ö))œk", "also:œ_ö_œk"),
47+
(
48+
"A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000",
49+
"a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000_0"
50+
),
51+
];
52+
53+
group.bench_function("normalize_service", |b| {
54+
b.iter_batched_ref(
55+
|| cases.iter().map(|(c, _)| c.to_string()).collect::<Vec<_>>(),
56+
|cases| {
57+
for c in cases {
58+
datadog_trace_normalization::normalize_utils::normalize_service(c);
59+
}
60+
},
61+
BatchSize::NumIterations(100000),
62+
)
63+
});
64+
}
65+
66+
fn normalize_name_bench(c: &mut Criterion) {
67+
let mut group = c.benchmark_group("normalization");
68+
let cases = &[
69+
"good",
70+
"bad-name",
71+
"Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.",
72+
];
73+
for case in cases {
74+
group.bench_with_input(
75+
BenchmarkId::new("normalize_name", case),
76+
*case,
77+
|b, case| {
78+
b.iter_batched_ref(
79+
|| case.to_owned(),
80+
datadog_trace_normalization::normalize_utils::normalize_name,
81+
BatchSize::NumIterations(100000),
82+
)
83+
},
84+
);
85+
}
86+
}
87+
88+
criterion_group!(benches, normalize_service_bench, normalize_name_bench);
89+
criterion_main!(benches);

trace-normalization/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
#![deny(clippy::all)]
55

6-
pub mod normalizer;
7-
86
pub mod normalize_utils;
7+
pub mod normalizer;
8+
pub(crate) mod utf8_helpers;

0 commit comments

Comments
 (0)