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

Multi-dimension SArray is allocating huge memories at first time run #976

Closed
islent opened this issue Dec 7, 2021 · 4 comments
Closed

Comments

@islent
Copy link

islent commented Dec 7, 2021

using StaticArrays
a = rand(10,10);
b = rand(50,50);
c = rand(100,100);

@time SMatrix{10,10}(a)
@time SMatrix{50,50}(b)
@time SMatrix{100,100}(c)

Results:

julia> @time SMatrix{10,10}(a)
  0.136969 seconds (340.05 k allocations: 18.051 MiB, 99.78% compilation time)
10×10 SMatrix{10, 10, Float64, 100} with indices SOneTo(10)×SOneTo(10):
# Omit Array output

julia> @time SMatrix{50,50}(b)
  1.306580 seconds (1.87 M allocations: 64.299 MiB, 0.73% gc time, 99.98% compilation time)
50×50 SMatrix{50, 50, Float64, 2500} with indices SOneTo(50)×SOneTo(50):
# Omit Array output

julia> @time SMatrix{100,100}(c)
ERROR: syntax: invalid syntax (memory-error out of gc handles)
Stacktrace:
 [1] top-level scope
   @ REPL[7]:1

@time SMatrix{100,100}(c) runs a long time, and the memory occupation can reach ~ 4GB

Test environment:

(@v1.7) pkg> st StaticArrays
      Status `E:\.julia\environments\v1.7\Project.toml`
  [90137ffa] StaticArrays v1.2.13

julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) W-10885M CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_DEPOT_PATH = E:\.julia
  JULIA_NUM_THREADS = 1
  JULIA_EDITOR = code
@mateuszbaran
Copy link
Collaborator

This is a known issue. Due to the way StaticArrays.jl is designed, it is preferable to use normal arrays when the total length is more than roughly 50 to 500.

@islent
Copy link
Author

islent commented Dec 7, 2021

Got it! I did not take notice of note in README:

Note that in the current implementation, working with large StaticArrays puts a lot of stress on the compiler, and becomes slower than Base.Array as the size increases. A very rough rule of thumb is that you should consider using a normal Array for arrays larger than 100 elements.

Will it be fixed in the future?

@mateuszbaran
Copy link
Collaborator

I doubt it. I wouldn't expect any significant development to happen in StaticArrays.jl (only bug fixing and minor features) and this is a big issue.

@islent
Copy link
Author

islent commented Dec 7, 2021

Sad to hear that. Closing issue...

@islent islent closed this as completed Dec 7, 2021
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

2 participants