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

slowdown with Val dispatch in v0.6 #21730

Closed
ghost opened this issue May 6, 2017 · 6 comments
Closed

slowdown with Val dispatch in v0.6 #21730

ghost opened this issue May 6, 2017 · 6 comments
Assignees
Labels
performance Must go faster regression Regression in behavior compared to a previous version

Comments

@ghost
Copy link

ghost commented May 6, 2017

using BenchmarkTools
const f32 = 0
jltype(::Val{f32}) = Float32
get_type(i) = jltype(Val{i}())
@benchmark get_type(f32)

Is almost hundred times slower with 0.6 (40 ns with v0.5 vs 4 μs with v0.6). Causes significant slowdown in ArrayFIre.jl package when types have to inferred.

@timholy
Copy link
Member

timholy commented May 7, 2017

That's a textbook example of misusing Val. https://docs.julialang.org/en/latest/manual/performance-tips.html#Types-with-values-as-parameters-1. Not that it wouldn't be good to fix the performance difference, but it's fundamentally non-inferrable.

@yuyichao yuyichao changed the title slowdown with Val type inference in v0.6 slowdown with Val dispatch in v0.6 May 7, 2017
@JeffBezanson JeffBezanson added performance Must go faster regression Regression in behavior compared to a previous version labels May 7, 2017
@JeffBezanson
Copy link
Member

Seems related to #21323. In this case since there is a 0-arg constructor we're forced to dispatch on the type instead of other arguments.

@JeffBezanson JeffBezanson self-assigned this May 7, 2017
JeffBezanson added a commit that referenced this issue May 9, 2017
For the `Type` method table, use the top-level `any` cache to split
based on whether the first argument is a leaf type. Leaf types
use the hash table, and non-leaf types skip the first argument and
try to split on the second argument instead.
JeffBezanson added a commit that referenced this issue May 9, 2017
For the `Type` method table, use the top-level `any` cache to split
based on whether the first argument is a leaf type. Leaf types
use the hash table, and non-leaf types skip the first argument and
try to split on the second argument instead.
JeffBezanson added a commit that referenced this issue May 17, 2017
For the `Type` method table, use the top-level `any` cache to split
based on whether the first argument is a leaf type. Leaf types
use the hash table, and non-leaf types skip the first argument and
try to split on the second argument instead.
JeffBezanson added a commit that referenced this issue Jun 1, 2017
For the `Type` method table, use the top-level `any` cache to split
based on whether the first argument is a leaf type. Leaf types
use the hash table, and non-leaf types skip the first argument and
try to split on the second argument instead.
JeffBezanson added a commit that referenced this issue Jun 30, 2017
For the `Type` method table, use the top-level `any` cache to split
based on whether the first argument is a leaf type. Leaf types
use the hash table, and non-leaf types skip the first argument and
try to split on the second argument instead.
JeffBezanson added a commit that referenced this issue Jul 11, 2017
Uses the `any` cache to skip all non-leaf slots when a later slot
is splittable.
JeffBezanson added a commit that referenced this issue Jul 11, 2017
Uses the `any` cache to skip all non-leaf slots when a later slot
is splittable.
JeffBezanson added a commit that referenced this issue Jul 12, 2017
Uses the `any` cache to skip all non-leaf slots when a later slot
is splittable.
JeffBezanson added a commit that referenced this issue Jul 13, 2017
Uses the `any` cache to skip all non-leaf slots when a later slot
is splittable.
JeffBezanson added a commit that referenced this issue Jul 14, 2017
Uses the `any` cache to skip all non-leaf slots when a later slot
is splittable.
JeffBezanson added a commit that referenced this issue Jul 14, 2017
Uses the `any` cache to skip all non-leaf slots when a later slot
is splittable.
@musm
Copy link
Contributor

musm commented Aug 4, 2017

closed by ecff624 ?

@martinholters
Copy link
Member

martinholters commented Aug 4, 2017

No. I have 44ns on 0.5, 6μs on 0.6 and 1.8μs on master. So it has improved since 0.6, but it's nowhere close to 0.5.

EDIT: D'oh, that hasn't been merged yet, so it cannot fix the issue on master.

@KristofferC
Copy link
Member

900 ns now.

@oscardssmith
Copy link
Member

160ns now. Is that good enough to close?

@vtjnash vtjnash closed this as completed Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

7 participants