-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Array indexing with UInt is ~5x slower than with Int #17103
Comments
Examining The elegant solution is probably to define all |
Cc @timholy |
This can probably be tackled while we're in RC, or for 0.5.x. |
I just took a peek at this, and doing it properly is well beyond the scope of my interests and what I have time for (finishing off #16973), so I'm marking this as "up for grabs." The In the specific case of What's the use-case for indexing with unsigned integers, anyway? Arrays require |
The actual use-case would be limited; that would be why we have never noticed this performance problem until now. I noticed this problem while profiling a decompressor which uses an unsigned integer to specify a byte offset. I can avoid the performance degradation by using the |
Good and bad news on this. In v 0.5.0, Good: uint performance is only 20% slower than int. Bad: I think that is only because int had a 4x regression. |
How could we possibly have had that bad a regression on array indexing and not have noticed it? |
I cannot reproduce the regression on |
That's possible, I was comparing direct times and assuming that there wouldn't be a 4x difference between computers (silly me). In that case, should this be closed as the difference is now fairly negligible? |
I can still reproduce the |
The key is this:
If that's still the case, then the issue isn't in the complexity of the indexing fallbacks, but, rather, it's simply that we choose to use a checked conversion to This is particularly problematic since the optimal order of operations between checking bounds and index conversion is dependent on the index types themselves. |
Yes, indexes to an array are always converted to |
Update: For AbstractArrays, in general, we've now fixed the twice-conversion problems Tim mentions in #17103 (comment). We absolutely do need to convert to For |
I think this is fixed as far as we can with #29784. |
This is the benchmark script:
And the result:
I don't know the internal, but I guess an index value is converted to
Int
before accessing and inexact check imposes the cost on it.data[Int(i)]
results in the slowdown at the same level butdata[reinterpret(Int, i)]
doesn't show any slowdown.The text was updated successfully, but these errors were encountered: