LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

Very slow LinearAlgebra operations, because of missing precompilatrion

Open PallHaraldsson opened this issue 2 years ago • 3 comments

shell> time julia -e "@time [1.0 2; 3 4]^3.0"
  0.000008 seconds (8 allocations: 496 bytes)

real	0m13,028s
user	0m13,302s
sys	0m0,621s

Presumably since not precompiled into LinearAlgebra (it doesn't help using it first). At first I thought the machine had hung.

I would rather it not being precompiled, though, if it would bloat Base/sysimage. Is that or some other known/accepted reason for this. I'm just assuming missing precompilation.

shell> time julia -e "@time [1 2; 3 4]^3"
  0.000019 seconds (3 allocations: 288 bytes)

real	0m1,451s
user	0m1,792s
sys	0m0,555s

shell> time julia -e "@time exp([1 2; 3 4])"
  0.006198 seconds (10 allocations: 1008 bytes)

real	0m3,827s
user	0m4,146s
sys	0m0,614s

shell> time julia -e "@time exp([1.0 2; 3 4])"
  0.000185 seconds (15 allocations: 1.188 KiB)

real	0m3,908s
user	0m4,284s
sys	0m0,560s

I actually meant to time exp, or to see if it worked at all, just mixed up with ^and discovered the slowness of it, since I see it here:

https://github.com/sethaxen/ExponentialAction.jl

and exp claimed to only work for Diagonals without that package. I can't confirm that, also should this be added to Juliað LinearAlgebra?

PallHaraldsson avatar Oct 31 '23 13:10 PallHaraldsson

we can't precompile everything, is there a specific reason why this should be precompiled?

Moelf avatar Oct 31 '23 13:10 Moelf

we can't precompile everything

It seemingly hanged, even for a very small matrix. It's not a very good look. It's not a priority for me. I don't know if we can precompile all of it or just part of it to make a bit faster, or should just skip. But I actually think we CAN precompile all... Like would happen with e.g. NumPy...

Feel free to close. I just wanted to bring this up in case not intended. It was much more of an issue when packages were not precompiled, to limit the sysimage. And I would actually want this NOT precompiled if it adds to it. LinearAlgebrea is about to be excised, seemingly, but some operations like that one are usable without using LinearAlgebra. Does that mean they are (or must be in Base)?

PallHaraldsson avatar Oct 31 '23 14:10 PallHaraldsson

The issue in the first case isn't with precompilation, but with poor type-inference due to recursion. This may certainly be improved.

jishnub avatar Oct 31 '23 17:10 jishnub