-
-
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
Inline constant arrays #5024
Comments
Of course, I didn't check to see if #3796 handles this... |
To avoid changing behavior, this kind of optimization (not sure I'd call it inlining) would require us to know that |
I missed #5008. This should probably be moved there... |
To make matters worse, I guess that what it would need to figure out is that a given array, during its lifetime, is used only for the constant values stored in it, and not for it's identity. And that's not even true if you look inside the implementation of |
Correct that this is a far harder optimization to pull off than it seems. |
What if constant arrays were made (deeply) immutable? Immutable arrays don't current exist in mainline julia, of course. |
I think this issue would be solved if one would use a tuple (representing a fixed size array, see #5857) instead of |
Wondering using tuple would make optimization easier. |
This version runs much faster
When defining |
Oh I further see that this would require that |
I just ran timings on my machine (v 0.5.0) and it looks like this difference in timing is now gone. (although there still is lots of memory allocation, and tknpp's version is still 10x faster). Should this be closed? |
I believe the current thinking is that cases like this are handled by https://github.com/JuliaArrays/StaticArrays.jl. |
I just ran across a comment on Wes McKinney's old blog post on Julia, where the following function was posted:
Ignoring the known issue that
+=
allocates memory, the constant expression also seems to be reallocated for each loop; moving this outside the loop cuts the time by 1/3:I'll also note that removing
+=
but leaving assignment ofp
inside the loop still allocatesp
every iteration:Moving
p
outside drops the time to .005 sec, since almost no memory is allocated.(Almost all of this is also obvious using the
code_*
functions.)The text was updated successfully, but these errors were encountered: