-
Notifications
You must be signed in to change notification settings - Fork 21
test(profiling): add profiles dictionary benchmarks #2088
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
Open
taegyunkim
wants to merge
7
commits into
main
Choose a base branch
from
taegyunkim/prof-14423-prof-dictinary-bench
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
477834f
test(profiling): add profiles dictionary benchmarks
taegyunkim 79a6152
Define consts and update comments
taegyunkim 90514f9
drop inner black_box
taegyunkim 8121b66
add comments
taegyunkim b123964
impl varying length strings
taegyunkim e4a91af
add comment why the function partitions the strins
taegyunkim 5c54a65
Merge branch 'main' into taegyunkim/prof-14423-prof-dictinary-bench
taegyunkim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use criterion::{black_box, criterion_group, BatchSize, BenchmarkId, Criterion, Throughput}; | ||
| use libdd_profiling::profiles::datatypes::ProfilesDictionary; | ||
| use std::sync::Barrier; | ||
| use std::thread; | ||
| use std::time::Duration; | ||
|
|
||
| const THREAD_COUNTS: [usize; 4] = [1, 2, 4, 16]; | ||
| const STRINGS_PER_THREAD: usize = 1024; | ||
| // Bound one generated function-name component so the input has repeated | ||
| // function-like fragments while each full string stays unique. | ||
| const FUNCTION_NAME_VARIANTS: usize = 97; | ||
| const STRING_SHAPE_VARIANTS: usize = 4; | ||
| // Knuth/Fibonacci multiplicative hash constant, used only to vary synthetic input. | ||
| const KNUTH_MULTIPLICATIVE_HASH: usize = 2_654_435_761; | ||
|
|
||
| // The outer Vec partitions precomputed input by benchmark worker thread; each | ||
| // inner Vec is the set of strings inserted by one worker. | ||
| fn make_partitioned_strings(thread_count: usize) -> Vec<Vec<String>> { | ||
| (0..thread_count) | ||
| .map(|thread_id| { | ||
| (0..STRINGS_PER_THREAD) | ||
| .map(|string_id| { | ||
| let function_id = string_id % FUNCTION_NAME_VARIANTS; | ||
| let mixed_id = string_id.wrapping_mul(KNUTH_MULTIPLICATIVE_HASH); | ||
|
|
||
| match string_id % STRING_SHAPE_VARIANTS { | ||
| 0 => format!("function_{function_id}::{mixed_id}"), | ||
| 1 => format!("/src/thread_{thread_id}/module_{function_id}/file_{string_id:04}.rs"), | ||
| 2 => { | ||
| format!("datadog::profiling::module_{function_id}::function_{mixed_id}") | ||
| } | ||
| _ => format!( | ||
| "/opt/datadog/profiler/thread-{thread_id}/module-{function_id}/src/file_{string_id:04}.rs::function_{function_id}::{mixed_id}", | ||
| ), | ||
| } | ||
| }) | ||
| .collect() | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| fn insert_profile_strings(dict: &ProfilesDictionary, strings: &[String]) { | ||
|
taegyunkim marked this conversation as resolved.
|
||
| for string in strings { | ||
| black_box(dict.try_insert_str2(string.as_str()).unwrap()); | ||
| } | ||
| } | ||
|
|
||
| fn insert_dictionary_strings_concurrently(strings: &[Vec<String>]) -> ProfilesDictionary { | ||
| let dict = ProfilesDictionary::try_new().unwrap(); | ||
|
|
||
| if let [strings] = strings { | ||
|
taegyunkim marked this conversation as resolved.
|
||
| insert_profile_strings(&dict, strings); | ||
| return dict; | ||
| } | ||
|
|
||
| let barrier = Barrier::new(strings.len()); | ||
| thread::scope(|scope| { | ||
| for thread_strings in strings { | ||
| let dict = &dict; | ||
| let barrier = &barrier; | ||
| scope.spawn(move || { | ||
| barrier.wait(); | ||
| insert_profile_strings(dict, thread_strings); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| dict | ||
| } | ||
|
|
||
| pub fn bench_profiles_dictionary(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("profiles_dictionary/unique_string_inserts"); | ||
| group.warm_up_time(Duration::from_secs(1)); | ||
| group.measurement_time(Duration::from_secs(5)); | ||
| group.sample_size(10); | ||
|
|
||
| for thread_count in THREAD_COUNTS { | ||
| // Precompute input outside the measured closure so the benchmark measures | ||
| // dictionary insertion rather than string formatting/allocation. | ||
| let strings = make_partitioned_strings(thread_count); | ||
| let total_strings = thread_count * STRINGS_PER_THREAD; | ||
| group.throughput(Throughput::Elements(total_strings as u64)); | ||
| group.bench_with_input( | ||
| BenchmarkId::new("threads", thread_count), | ||
| &strings, | ||
| |b, strings| { | ||
| b.iter_batched( | ||
| || strings, | ||
| |strings| black_box(insert_dictionary_strings_concurrently(strings)), | ||
| BatchSize::LargeInput, | ||
| ); | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!(benches, bench_profiles_dictionary); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.