-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Avoid inlining setindex!(::Array, ::Any, ::AbstractVector) #21401
Conversation
@_propagate_inbounds_meta forces inlining, which may not be desirable for such complex functions. To avoid this, define a wrapper which will be inlined, and which will call either the safe or the unsafe method.
What is the impact of this change? |
In terms of? The idea is to avoid always inlining |
I mean, why do I care? What is the benefit? |
Well, just like for any relatively large function, inlining makes the code bigger and it's not necessarily a win in terms of performance, so better leave the compiler heuristics decide what to do. I guess you'd better ask @simonster. :-) |
The CI failure is quite obscure and comes from x = ["a"]
x[.!trues(1)] This in turns comes from the fact that |
I've tracked down the failure to the |
This generally seems like the right thing to do — we do something similar for the generic versions in multidimensional.jl. It's a little unfortunate that it's so complicated and is an exact duplication of that functionality, but I imagine the comment about it being required for bootstrap is still true. |
|
I've just tried removing them, and indeed bootstrap fails.
You mean, with the patch from this PR applied? Else it doesn't happen. For some reason, this PR triggers the existing bug in more cases than previously. |
Doh, of course. Sorry for the noise. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
Is this still relevant after #22210? |
I guess so, since this PR is about avoiding forced inlining, which will allow the compiler to decide whether it's best to inline or not. |
#22210 didn't, in the end, remove any of the
|
@_propagate_inbounds_meta
forces inlining, which may not be desirablefor such complex functions. To avoid this, define a wrapper which will be
inlined, and which will call either the safe or the unsafe method.
Follows a suggestion by @simonster at #20910 (comment). Unfortunately, this makes the code significantly more complex; maybe there's a way to make this slightly cleaner.
FWIW, it turns out that the compiler decides to inline
_unsafe_setindex!
when@inbounds
is passed, but_safe_setindex!
remains as a function call.