- Sponsor
-
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 keyword? #1106
Comments
It's ugly, but this is something every compiler needs eventually. In this particular case the functions are all small so we can probably do better without a declaration, but there will always be big functions you want inlined even though the compiler would never do it on its own. |
The other day I was thinking would be great a macro |
When we've discusses this the notion of using online at the call site came up. I think both a function modifier and a call site hint would be good to be able to do. |
Bump. In playing around with iteration via immutables, I noticed just how crucial it is that With iteration, since |
Case in point: https://gist.github.com/timholy/5108548. This uses the brand-new In contrast to the 1D case I tested here: I even turned off gc, which led to a disturbingly-large improvement for something that really should be doing no gc whatsoever (and with it enabled, SProfile captures lots of backtraces inside gc). |
Actually there's something really fishy going on: in that gist, if I just comment out the whole try/finally block---skipping the |
I believe the try/finally is forcing |
That's not it; I can comment out just the try/finally, and it still happens. If I had to guess, it's having a hard time inferring the output type of ref(A, iter::IteratorState). |
That's a relief; if that had been the problem it would have been a pain to fix :) We can try |
Looks like my guess was wrong too; The more telling aspect is the sprofile trace. With the Iterator1D you never see a backtrace inside julia> sprofile_tree(true) |
Shoot, with the lack of spacing that's uninterpretable. Here's the flat profile: Count File Function Line/offset |
So can this be closed in light of 2eaf48d? |
Did that get merged? |
I think that just covered function definition usage and not call site usage, right? |
Yeah, I'm thinking along the lines of const SHIFTEDMONTHDAYS = [306,337,0,31,61,92,122,153,184,214,245,275]
function totaldays(y,m,d)
# If we're in Jan/Feb, shift the given year back one
z = m < 3 ? y - 1 : y
mdays = SHIFTEDMONTHDAYS[m]
# days + month_days + year_days
return d + mdays + 365z + fld(z,4) - fld(z,100) + fld(z,400) - 306
end
function Date(y,m,d)
return totaldays(y,m,d)
end
function Date1(y,m,d)
return @inline totaldays(y,m,d)
end With results: In [4]: @code_llvm Date(2013,1,1)
define i64 @"julia_Date;38842"(i64, i64, i64) {
top:
%3 = call i64 @"julia_totaldays;38843"(i64 %0, i64 %1, i64 %2), !dbg !1615
ret i64 %3, !dbg !1615
}
In [5]: @code_llvm Date1(2013,1,1)
define i64 @"julia_Date1;38844"(i64, i64, i64) {
top:
%3 = call i64 @"julia_totaldays;38843"(i64 %0, i64 %1, i64 %2), !dbg !1618
ret i64 %3, !dbg !1618
} |
Right, currently this only affects function declaration. |
Closing this since we do have |
I think this was being left open because the 2nd type of inlining, call-site inlining, remains to be implemented. |
What are the thoughts on having an "inline" keyword? I've found a situation that could benefit from one:
Reflect is the hardest case to make efficient, because I can't get it to fully inline. If I manually inline, it's almost 3-fold faster than the best of these, which is the one not commented out.
The text was updated successfully, but these errors were encountered: