Maybe one additional note:

When we access elements of an array, that generally occurs with an offset to 
stackpointer. Stackpointer is generally fixed while we are inside a proc, and 
stackpointer is generally located in a register, so to access an array element 
a offset plus stackpointer is used to locacte the array element. If array index 
is a constant, then offset is constant too. If array index is a variable, than 
offset is product of element_size and offset. So there is a runtime mul in 
later case.

To access an element of a seq, there is some indirection: First the base 
address of the pointer to payload is moved into a CPU register, and an offset = 
(elementsize * index) is added to locate element. When we access many elements 
of a seq, then only one time its payload address needs to be moved into a CPU 
register, so accessing many elements is not really slower for seq than it is 
for array. 

Reply via email to