-
-
Notifications
You must be signed in to change notification settings - Fork 14
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 regression in Char -> String causing problems with Cholesky decomposition #557
Comments
So JuliaLang/julia#28873 should fix this. I'm getting a 1700x speedup for your example. |
Looks like JuliaLang/julia#28149 introduced the regression where a method for |
@andreasnoack thanks very much for the quick fix to |
One further oddity with this Char -> String issue
(BTW: I think the "strings" label is probably more appropriate than "linear algebra" for this issue as the Cholesky performance regression is a symptom rather than a cause.) |
FWIW, the majority of the slowness here is from the dynamic dispatch:
Just copy pasting the definition improves performance 7x.
|
Actually my testing shows that the offending line is:
as in the old implementation we had When I changed this I thought it is not important, but it seems it is crucial :). We should change line:
to something like:
to ensure minimum buffer size greater than |
It helps but still
is significantly slower than in 0.6. The dynamic dispatch penalty is still large though since after "refreshing" the function by reevaluating we have
|
Interesting - I presumably saw the second test in my execution. Can you explain why reevaluating Nevertheless, I think that the slowness comes from the keyword argument If yes then two changes would be in order:
What do you think? EDIT: and do you know the reason of dynamic dispatch in this case? It should dispatch statically. |
After JuliaLang/julia#28683 I only trust the result from a freshly recompiled sysimg. With diff --git a/base/strings/io.jl b/base/strings/io.jl
index 64b9a613c0..75b79c02fa 100644
--- a/base/strings/io.jl
+++ b/base/strings/io.jl
@@ -103,31 +103,35 @@ function sprint(f::Function, args...; context=nothing, sizehint::Integer=0)
String(resize!(s.data, s.size))
end
-tostr_sizehint(x) = 0
+tostr_sizehint(x) = 8
tostr_sizehint(x::AbstractString) = lastindex(x)
tostr_sizehint(x::Float64) = 20
tostr_sizehint(x::Float32) = 12
-function print_to_string(xs...; env=nothing)
+function print_to_string(xs...)
if isempty(xs)
return ""
end
# specialized for performance reasons
s = IOBuffer(sizehint=tostr_sizehint(xs[1]))
- if env !== nothing
- env_io = IOContext(s, env)
- for x in xs
- print(env_io, x)
- end
- else
- for x in xs
- print(s, x)
- end
+ for x in xs
+ print(s, x)
end
String(resize!(s.data, s.size))
end
-string_with_env(env, xs...) = print_to_string(xs...; env=env)
+function string_with_env(env, xs...)
+ if isempty(xs)
+ return ""
+ end
+ # specialized for performance reasons
+ s = IOBuffer(sizehint=tostr_sizehint(xs[1]))
+ env_io = IOContext(s, env)
+ for x in xs
+ print(env_io, x)
+ end
+ String(resize!(s.data, s.size))
+end
"""
string(xs...) I am getting julia> @btime Base.print_to_string('a')
77.522 ns (3 allocations: 160 bytes)
"a"
julia> @btime Base.print_to_string("", 'a')
165.129 ns (4 allocations: 192 bytes)
"a"
julia> @btime Base.print_to_string('b', 'a')
89.995 ns (3 allocations: 160 bytes)
"ba" |
A significant performance regression was noted on Discourse with multi-variate normal random number generation with Distributions.jl. After digging through the code I found that the performance difference was due to regressions in the performance of the Cholesky decomposition; specifically on v0.6.4 we have
whereas on v1.0.0 we have
Digging further, the problem appears to be the line
Symbol(Cuplo) == :U
ingetproperty
for the Cholesky decomposition. This creates a Symbol from a Char which callsSymbol(string(x...))
.Looking at
string('U')
on v0.6.4 giveswhereas on v1.0.0
The code corresponding to
string(Char)
appears to have changed significantly between v0.6.4 and v1.0.0 so that's as far as I can go...The text was updated successfully, but these errors were encountered: