> I do not understand the use of the openarray parameter in relation to 
> performance.

`openarray` has nothing to do with performance. It is just a feature to allow 
implementing procs that take both an `array` and a `seq` as parameter.

The actual performance gain stems from using arrays instead of seqs. Because an 
array's length is known at compile time, it can be allocated on the stack. Seqs 
always need to be allocated on the heap. Therefore, it is always advisable to 
use arrays when possible. Other performance optimizations are explained in the 
previous posts.

> If the length of the output array of a proc is not known in advance, are 
> there general rules to accomplish a good performance?

If you can calculate the target length of the array efficiently before actually 
filling it, initialize the result seq with as many elements as needed (as shown 
in the other posts) or use `newSeqOfCap` if you're on devel or once this has 
made it into a release.

Reply via email to