-
Notifications
You must be signed in to change notification settings - Fork 147
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
isassigned is slow for out-of-range indices #1152
Comments
There used to be a (faulty) What do you need a performant |
The logic was something like "given an array and an index, see if index + 1 is a valid index and access array there if so". I was using it in my package here: Although I've since replaced it with |
Thanks, that makes sense, (Although note that Base's |
MWE:
This is because Base's fallback implementation uses a try/catch, which is slow in the catch case:
https://github.com/JuliaLang/julia/blob/def2ddacc9a9b064d06c24d12885427fb0502465/base/abstractarray.jl#L605-L616
This really hurts performance when
isassigned
is being used in a case where the index is really expected to be out-of-range sometimes. I even wonder if Base's fallback implementation is just a bad idea, because it will always be slow in this case: something likei in eachindex(arr)
would at least be faster for static arrays.Using Julia 1.9 and StaticArrays v.1.5.12
The text was updated successfully, but these errors were encountered: