perl arrays keep a "start-of-array" number in their datastructures, so using shift() usually doesn't move any items at all and it's generally pretty efficient to shift() even very large arrays.
shift never moves any items, and thus it's extremely efficient no matter the size of the array.
@a = qw( a b c );
+---+---+---+---+
@a = | a | b | c | X | ( X = spare )
+---+---+---+---+
^ ^
| |
start end
shift @a;
+---+---+---+---+
@a = | X | b | c | X |
+---+---+---+---+
^ ^
I'm assuming shift/push combos move stuff around every once in a while, since I write code that depends on that behaviour and it seems to work, but I'm only 90% certain on that.
It's not the shift/push combo, it's push alone that causes the moving.
For efficiency, arrays can have more elements allocated than necessary. If a push is performed, these spare elements will be used. If a push is performed and there no spare elements, a new bigger array is allocated and the elements (pointers) are moved to the new array. This occurs whether shift was used or not.
[ continuing from above ]
push @a, 'd';
+---+---+---+---+
@a = | X | b | c | d |
+---+---+---+---+
^ ^
push @a, 'e';
-> No more space! Re-allocation occurs.
-> $new_buf_size = $old_buf_size * 2 + 4
-> Pointers to elements are quickly
copied to newly allocated buffer.
+---+---+---+---+
| X | b | c | d |
+---+---+---+---+
/ / /
/ / /
/ / /
v v v
+---+---+---+---+---+---+---+---+---+---+---+---+
@a = | b | c | d | e | X | X | X | X | X | X | X | X |
+---+---+---+---+---+---+---+---+---+---+---+---+
^ ^