Improve performance for array iteration