You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
Right now, inside a loop that mutates an array, for each iteration, there is a mutability check in each iteration. With the bound check elimination, this is the remaining additional overhead inside loops for arrays, in addition to make arrays content is 16-byte aligned, that would prevent advanced optimizations like vectorization.
So my proposal would be to use a precondition before the loop that the user can place. For example:
val array = IntArray(64)
array.ensureNotFrozen()
for (n in 0 until array.size) {
array[n] = n
}
It is possible to remove in codegen the array set mutability check, if it can be proven that the array is not mutated somewhere else. For example if only pure functions (not sure if the IR have information about pureness) are called in all the predecessors CFG nodes before the set and after the check. The precondition could be automatically added inside the if, before the do..while loop generated for fors as an advanced optimization.
Maybe not trivial to implement, but worth trying at least after 1.0 is released.
Another option would be to add an annotation for methods like @UnsafeNotCheckMutability for making hot paths as much optimized as possible.
The text was updated successfully, but these errors were encountered:
Right now, inside a loop that mutates an array, for each iteration, there is a mutability check in each iteration. With the bound check elimination, this is the remaining additional overhead inside loops for arrays, in addition to make arrays content is 16-byte aligned, that would prevent advanced optimizations like vectorization.
So my proposal would be to use a precondition before the loop that the user can place. For example:
It is possible to remove in codegen the array set mutability check, if it can be proven that the array is not mutated somewhere else. For example if only pure functions (not sure if the IR have information about pureness) are called in all the predecessors CFG nodes before the set and after the check. The precondition could be automatically added inside the if, before the do..while loop generated for fors as an advanced optimization.
Maybe not trivial to implement, but worth trying at least after 1.0 is released.
Another option would be to add an annotation for methods like
@UnsafeNotCheckMutability
for making hot paths as much optimized as possible.The text was updated successfully, but these errors were encountered: