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

Remove union penalties for inlining cost #50429

Merged
merged 1 commit into from
Jul 7, 2023
Merged

Remove union penalties for inlining cost #50429

merged 1 commit into from
Jul 7, 2023

Conversation

Keno
Copy link
Member

@Keno Keno commented Jul 5, 2023

I added this code back in #27057, when I first made Union-full signatures inlineable. The justification was to try to encourage the union splitting to happen on the outside. However (and I believe this changed since this code was introduced), these days inference is in complete control of union splitting and we do not take inlineability or non-inlineability of the non-unionsplit function into account when deciding how to inline. As a result, the only effect of the union split penalties was to prevent inlining of functions that are not union-split eligible (e.g.
+(::Vararg{Union{Int, Missing}, 3})), but are nevertheless cheap by our inlining metric. There is really no reason not to try to inline such functions, so delete this logic.

@Keno Keno closed this Jul 6, 2023
@Keno Keno deleted the kf/rmunionpenalties branch July 6, 2023 00:32
@Keno Keno restored the kf/rmunionpenalties branch July 6, 2023 00:32
@Keno Keno reopened this Jul 6, 2023
@aviatesk
Copy link
Sponsor Member

aviatesk commented Jul 6, 2023

@nanosoldier runbenchmarks(!"scalar", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@oscardssmith
Copy link
Member

oscardssmith commented Jul 6, 2023

nanosoldier seems pretty ambivalent. There are only 2 that are over 20% regressions:

["misc", "23042", "ComplexF32"] | 1.51 (5%) | 1.00 (1%)
["simd", ("Cartesian", "conditional_loop!", "Int32", 2, 31)] | 1.99 (20%) | 1.00 (1%)

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 6, 2023

It sounds fine to me to remove, but you need to fix the offsetarray test that it breaks

Error in testset offsetarray:
Test Failed at /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:630
  Expression: #= /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:630 =# @allocated(maximum!(R, B)) <= 800
   Evaluated: 1264 <= 800
Error in testset offsetarray:
Test Failed at /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:632
  Expression: #= /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:632 =# @allocated(minimum!(R, B)) <= 800
   Evaluated: 1264 <= 800
Error in testset offsetarray:
Test Failed at /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:636
  Expression: #= /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:636 =# @allocated(maximum!(R, B)) <= 800
   Evaluated: 1264 <= 800
Error in testset offsetarray:
Test Failed at /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:638
  Expression: #= /cache/build/default-amdci4-0/julialang/julia-master/julia-3a876cbcb2/share/julia/test/offsetarray.jl:638 =# @allocated(minimum!(R, B)) <= 800
   Evaluated: 1264 <= 800

Keno added a commit that referenced this pull request Jul 6, 2023
The change in #50429 moves around some dispatch boundaries and pushes
the allocations in the offsetarrays `maximum!` test over the limit.
The implementation of that code is massively type unstable. Somewhat,
ironically, the whole original point of that test was to test that
the implementation was not type-unstable (#28941), so actually opt our
OffsetArrays implementation into the interface that's supposed to
guarantee that.

If this PR is fine here, I'll submit the same upstream to avoid
diverging the implementations too much.
@Keno
Copy link
Member Author

Keno commented Jul 6, 2023

I looked at the test, but it turns out to just be actually failing what it was supposed to test and we just happened to bump the threshold. This PR changes the specialization boundaries, so it moves around some allocations, which could potentially be improved in codegen, but it's not clear to me that the generated code is actually worse, so I've split the fix to the test into #50447, bumped the threshold here and we can do any codegen improvements separately.

I added this code back in #27057, when I first made Union-full
signatures inlineable. The justification was to try to encourage
the union splitting to happen on the outside. However (and I believe
this changed since this code was introduced), these days inference
is in complete control of union splitting and we do not take
inlineability or non-inlineability of the non-unionsplit function
into account when deciding how to inline. As a result, the only
effect of the union split penalties was to prevent inlining of
functions that are not union-split eligible (e.g.
`+(::Vararg{Union{Int, Missing}, 3})`), but are nevertheless cheap
by our inlining metric. There is really no reason not to try to
inline such functions, so delete this logic.
@Keno Keno merged commit 21bb0c7 into master Jul 7, 2023
6 checks passed
@Keno Keno deleted the kf/rmunionpenalties branch July 7, 2023 15:43
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Jul 15, 2023
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Jul 15, 2023
DilumAluthge pushed a commit that referenced this pull request Sep 1, 2023
The change in #50429 moves around some dispatch boundaries and pushes
the allocations in the offsetarrays `maximum!` test over the limit. The
implementation of that code is massively type unstable. Somewhat,
ironically, the whole original point of that test was to test that the
implementation was not type-unstable (#28941), so actually opt our
OffsetArrays implementation into the interface that's supposed to
guarantee that.

If this PR is fine here, I'll submit the same upstream to avoid
diverging the implementations too much.

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

5 participants