Skip to content
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

Performance of map #196

Open
bkamins opened this issue Jun 12, 2022 · 2 comments
Open

Performance of map #196

bkamins opened this issue Jun 12, 2022 · 2 comments

Comments

@bkamins
Copy link

bkamins commented Jun 12, 2022

@tkf what is the reason of the following performance comparison? (this is a fresh Julia session on Win11 with 8 threads):

julia> Threads.nthreads()
8

julia> x = rand(10^8) .- 0.5;

julia> @time map(abs, x);
  0.251657 seconds (99.43 k allocations: 768.457 MiB, 18.93% gc time, 14.49% compilation time)

julia> @time map(abs, x);
  0.239117 seconds (3 allocations: 762.940 MiB, 22.72% gc time)

julia> using ThreadsX

julia> @time ThreadsX.map(abs, x);
  1.842571 seconds (2.53 M allocations: 4.024 GiB, 10.90% gc time, 33.76% compilation time)

julia> @time ThreadsX.map(abs, x);
  1.176356 seconds (1.51 k allocations: 3.888 GiB, 14.73% gc time)

If I use 1, 2, or 4 threads the situation is similar.

Thank you!

@MasonProtter
Copy link

MasonProtter commented May 4, 2023

Hoping to mitigate this somewhat with JuliaFolds/Transducers.jl#553. However, Transducers.jl (and by extension, ThreadsX.jl), is at it's worst when dealing with very fast functions like abs.

The easiest fix for you to get better performance would be to use ThreadsX.map!(abs, similar(x), x).

@jamblejoe
Copy link

I have the same problem on Apple M1:

julia> using ThreadsX

julia> Threads.nthreads()
4

julia> x = rand(10^8) .- 0.5;

julia> @time map(abs, x);
  0.365691 seconds (45.60 k allocations: 765.970 MiB, 16.88% gc time, 6.83% compilation time)

julia> @time map(abs, x);
  0.471808 seconds (3 allocations: 762.940 MiB, 14.60% gc time)

julia> @time ThreadsX.map(abs, x);
  1.776120 seconds (3.21 M allocations: 1.576 GiB, 12.86% gc time, 47.61% compilation time)

julia> @time ThreadsX.map(abs, x);
  1.761694 seconds (120 allocations: 2.340 GiB)
julia> versioninfo()
Julia Version 1.10.3
Commit 0b4590a5507 (2024-04-30 10:59 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 4 default, 0 interactive, 2 GC (on 4 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 4

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

No branches or pull requests

3 participants