-
-
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
Function caching issue with broadcast #9869
Comments
This is basically #265. (Like many julia developers, I didn't even have to look that up, I know that issue number by heart.) If you can solve that, @StefanKarpinski owes you a bottle of bourbon 😄. As you noted, broadcasting keeps track of functions in a Dict; functions are hashed by object_id, and so what you're seeing comes down to this: julia> f(x) = x^2
f (generic function with 1 method)
julia> object_id(f)
0x6582bd6b207f44ad
julia> f(x) = x^3
f (generic function with 1 method)
julia> object_id(f)
0x6582bd6b207f44ad To me it looks as if it just comes down to the pointer. |
Yeah, I kinda expected #265 to be involved (as per Mikes comment). Just a thought that would solve this problem:
(not |
Many functions have many methods available. Which body were you planning on choosing for But I should add that this is probably a "baby version" of #265, and might make a good step towards fixing it. The thing that makes this case far, far easier is that you explicitly call In what would be only a slight modification of your idea, conceivably one could just have a "version number" associated with each generic function which would be incremented each time a method was (re)defined, and hashing could incorporate the version number. |
The naive answer is "all of them", I guess. ;)
for all possible This idea might be expanded to introduce function hashing based only on the body of its methods, so that (in the case of But I do think that introducing a "version number" per function is more elegant (and easier and faster, probably). |
@Varanas, just to be clear: currently I'm not planning to tackle this, so if you need it I encourage you to give it a whirl. |
@timholy Mind if I ask how the caching in This issue seems strange to me because I've never seen #265 happen with functions as values – so I'm wondering if it's caused only by the caching, independently of that issue. (Of course, if you're sure it's #265's fault, I'll believe you ;) |
It's a close analog of #265, not #265 literally. The best answer to your question is here. Any questions? 😄 Briefly, what's happening is that you compile a (hidden) method specialized for (1) the input function (it inlines the input function, so it's fast), (2) the number of inputs arrays, and (3) the dimensionalities of the inputs. You stash this compiled function in a The reason why it's similar to #265 is because julia's global method table is a lot like that |
Ah ok – thanks for the explanation. If I understand correctly it sounds like it is essentially #265, in the sense that fixing 265 – i.e. recompiling the hidden method when the function it depends on is updated – would be sufficient to fix it. It's actually possible to check if the method has been updated already, though. For example:
This object will change if the method is updated, so |
Just be aware of the performance issues which led to the current code, see JuliaLang/LinearAlgebra.jl#89 and #6107. |
This should be closed now that #17057 is merged. |
An issue with broadcasting came up in the Juno forums and I couldn't find anything relevant in the mailing list or here.
From a brief look at the code
broadcast
caches functions - this seems to lead to redefined methods being ignored when usingbroadcast
again.This means fun stuff like
I do hope that this is not the intended behaviour - should it be, this certainly needs to be added to the docs.
versioninfo:
(Doesn't look like the relevant code has changed on master though, so it should 'work' there too)
The text was updated successfully, but these errors were encountered: