Skip to content

Commit 52dcbad

Browse files
authored
Use faster PRNG in the allocations profiler (JuliaLang#57761) (#222)
* Use faster PRNG in the allocations profiler (JuliaLang#57761) `rand()` locks and is slow. This uses the seed from `ptls`. * Use correct arguments for 1.10's `cong()` Also remove a warning from array.c
1 parent 36d926f commit 52dcbad

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ STATIC_INLINE void jl_array_grow_at_beg(jl_array_t *a, size_t idx, size_t inc,
801801
size_t nbinc = inc * elsz;
802802
char *data = (char*)a->data;
803803
char *newdata;
804-
char *typetagdata;
804+
char *typetagdata = NULL;
805805
char *newtypetagdata = NULL;
806806
int isbitsunion = jl_array_isbitsunion(a);
807807
if (isbitsunion) typetagdata = jl_array_typetagdata(a);

src/gc-alloc-profiler.cpp

Lines changed: 2 additions & 1 deletion
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, 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)