-
Notifications
You must be signed in to change notification settings - Fork 41
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 OffsetArray constructors #164
Conversation
Codecov Report
@@ Coverage Diff @@
## master #164 +/- ##
==========================================
- Coverage 99.21% 98.95% -0.27%
==========================================
Files 4 8 +4
Lines 256 477 +221
==========================================
+ Hits 254 472 +218
- Misses 2 5 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't get inlined now due to length(::UnitRange{Int})
having two checked-arithmetic operations. (See Base.print_statement_costs
on 1.6.) This seems reasonable, and gives Julia a chance to elide the wrapper in the caller.
src/OffsetArrays.jl
Outdated
@boundscheck overflow_check.(axes(parent), offsets) | ||
overflow_check.(axes(parent), offsets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this would allocate an array, is that completely elided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thought. Really this should be a foreach
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, turns out map
is faster here.
- map: 3.004ns
- foreach: 5.261 ns
Is there a way to check if a method is properly inlined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach
doesn't force-specialize on the function. It could probably use some love...
I would guess, though, that it's elided. It should be creating a tuple (not an array) and that should get elided.
Is there a way to check if a method is properly inlined?
@code_typed
or Cthulhu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would guess, though, that it's elided. It should be creating a tuple
Yea looks from the benchmarks that it is elided, it's just not immediatly obvious from the code (I didnt't think about the inputs beeing tuples). map
is probably fine then (with a comment?) although something like foreach
would be more typical when you don't care about the result I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
on tuple can be optimized by the compiler and thus not usingforeach
here
This is what I added. Unsure what's the terminology here, "constant folding"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just say "optimized away." Another option would be DCE.
To reduce the overhead