Skip to content

Commit 4db8c1b

Browse files
authored
Use faster PRNG in the allocations profiler (#57761)
`rand()` locks and is slow. This uses the seed from `ptls`.
1 parent 2f54acb commit 4db8c1b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/gc-alloc-profiler.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ void _maybe_record_alloc_to_profile(jl_value_t *val, size_t size, jl_datatype_t
138138

139139
auto& profile = global_profile.per_thread_profiles[thread_id];
140140

141-
auto sample_val = double(rand()) / double(RAND_MAX);
141+
jl_ptls_t ptls = jl_current_task->ptls;
142+
auto sample_val = double(cong(UINT64_MAX, &ptls->rngseed)) / double(UINT64_MAX);
142143
auto should_record = sample_val <= global_profile.sample_rate;
143144
if (!should_record) {
144145
return;

0 commit comments

Comments
 (0)