-
-
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
Allocation regression: global const getfield allocates in some cases #50317
Comments
Thanks @KristofferC. It looks like the regressions were identified last November: Did we decide we will just accept these for 1.9? Is there anything that can be done to address them? They are currently having quite significant impact in our upgrade attempts. |
Not sure what you mean, 1.9 is already out.
Fix it and backport the fix I would assume. |
I meant: back in November, when this issue was identified, there weren't any follow up comments. So did we explicitly decide that the regression was acceptable for the (then) upcoming release? Or was it accidentally missed? I'm asking because if it was just accidentally missed, there's still hope that it's an easy fix. If it was explicitly decided that we would live with it, then maybe there are reasons it will be hard to fix for a 1.9.2. Sorry for my sloppy / confusing language. :) |
Somebody just needs to decide what it should do and what the inlining rules are. |
To expand on that, the issue here is that the compiler improved, so we now know the constant result of the getproperty.
|
The third choice seems like the easiest way forward here, and additionally, seems like it will address our problem. Can we request that fix as it's beyond my understanding? |
Looking at bbdee0b#commitcomment-89859406 it seems it got missed and never got "promoted" from a comment to a milestoned issue. |
Thanks Kristoffer. 👍 +1 that it would be great to get this resolved. It's currently blocking our upgrade since, like I said, it's making all locks+unlocks in a core component (our pager) noticeably slower. We're seeing like a 20%+ regression in some workloads I think? |
As already noted in linked issues, a workaround is to use getters: struct Wrapper
lock::ReentrantLock
end
get_lock(w::Wrapper) = w.lock
Base.lock(f::Function, m::Wrapper) = Base.lock(f, get_lock(m))
Base.lock(m::Wrapper) = Base.lock(get_lock(m))
Base.unlock(m::Wrapper) = Base.unlock(get_lock(m))
const MONITOR = Wrapper(ReentrantLock())
function foo()
Base.@lock MONITOR begin
return 2+2
end
end
foo()
@time foo() # zero allocs |
Thanks @nsajko. We're trying this with one of our data structures but the trouble is that we'd have to make this change in a number of different places. |
Let me post a gist of discussion we had on Slack. @Keno said:
And I believe that in particular the latter optimization is relatively easier to implement. It basically extends this optimization at the codegen level for Lines 3737 to 3821 in feb2988
|
Here's a small regression that is showing up pretty large in the RAI codebase (we have a global lock in our database pager that's way slower now).
Somehow accessing the fields of a global constant has become type unstable in some cases.
The allocation only shows up when referencing the global const variable. It disappears if you pass it in as an argument:
This might be related to #50073, but i'm not sure.
The text was updated successfully, but these errors were encountered: