I've been benchmarking a bit to see how different things work (in Arturo) and one of these is: concatenation/appending-to an array vs a string.
The exact same operation is slower for arrays than for strings. Which is not so surprising. What is surprising is that what I'm calculating is roughly ~150 times slower. And yes, there must be some Arturo-related overhead, but I assure you it has nothing to do with such a difference.
So... obviously, I look into it array implementation and the culprit seems to be a constant copying of the array in question - which is not the case for strings, although supposedly we are talking about something extremely similar (arrays of characters vs arrays of something else).
So... the question is... is there any other approach to this, so that the 2 operations don't differ in performance in such an extreme way?
The procs in system above with the signature proc `&`*[T](x, y: sink seq[T]): seq[T] (notice sink) are supposed to optimize by using inplace add (which will not always copy), but they don't seem to do so. Using add, if possible, is what you are supposed to do.
Copying strings is computationally trivial because they are guaranteed to not contain complex types like seqs might. You can just copy their entire block of memory verbatim once. That can definitely be tens or hundreds of times faster than copying individual items.
Something else is, range checks do not seem to be disabled in that part of the system module, so every single item access will create a range check. This doesn't matter if you are compiling with -d:danger, but it can massively decrease performance on -d:release and lower optimization levels (https://github.com/nim-lang/Nim/issues/20232).
Copying strings is computationally trivial because they are guaranteed to not contain complex types like seqs might. You can just copy their entire block of memory verbatim once. That can definitely be tens or hundreds of times faster than copying individual items.
Probably we can specialize array[T] with when supportsCopyMem(T) to use copyMem