Skip to content

Conversation

@kpamnany
Copy link
Member

rand() locks and is slow. This uses the seed from ptls.

`rand()` locks and is slow.
@kpamnany kpamnany requested a review from gbaraldi March 13, 2025 16:33
@kpamnany kpamnany merged commit 4db8c1b into master Mar 13, 2025
4 of 7 checks passed
@kpamnany kpamnany deleted the kp-allocprof-rand branch March 13, 2025 21:27
kpamnany added a commit to RelationalAI/julia that referenced this pull request Mar 13, 2025
`rand()` locks and is slow. This uses the seed from `ptls`.
kpamnany added a commit to RelationalAI/julia that referenced this pull request Mar 27, 2025
* 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
@NHDaly
Copy link
Member

NHDaly commented Mar 27, 2025

Before and after evidence of the improvement:

6 threads:

julia> @time let out = zeros(Int, 1000)
           Threads.@threads for i in 1:1000
               out[i] += sum(Any[rand(Int) for i in 1:300000])
           end
           sum(out)
       end
  1.987923 seconds (600.03 M allocations: 11.178 GiB, 42.80% gc time, 4.52% compilation time)
-7843380098545669747

julia> using Profile

julia> @time Profile.Allocs.@profile sample_rate=0.000001 begin
           let out = zeros(Int, 1000)
               Threads.@threads for i in 1:1000
                   out[i] += sum(Any[rand(Int) for i in 1:300000])
               end
               sum(out)
           end
       end
  8.568267 seconds (600.03 M allocations: 11.178 GiB, 9.67% gc time, 0.86% compilation time)
3995634343101539424

shows a significant difference.

After this PR, the difference is gone! 🎉

julia> @time let out = zeros(Int, 1000)
           Threads.@threads for i in 1:1000
               out[i] += sum(Any[rand(Int) for i in 1:300000])
           end
           sum(out)
       end
  1.934198 seconds (600.08 M allocations: 11.181 GiB, 43.48% gc time, 12.11% compilation time)
6985800949357430475

julia> using Profile

julia> @time Profile.Allocs.@profile sample_rate=0.000001 begin
           let out = zeros(Int, 1000)
               Threads.@threads for i in 1:1000
                   out[i] += sum(Any[rand(Int) for i in 1:300000])
               end
               sum(out)
           end
       end
  2.157459 seconds (600.03 M allocations: 11.178 GiB, 39.03% gc time, 3.48% compilation time)
6035867019842016171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants