perf: add lua iteration to decrease loops in lua
Move some of the iteration in to loa and access the values by the index
to reduce the number of loops we need todo to get items into teh results
buffer.
Currently the flow is:
- Filter and sort the candidates in rust
- Convert to a string and pass to lua
- Split the string and add them as lines in a buffer in lua
Now the flow is:
- Filter and sort the candidates in rust
- Loop over an iterator in lua
- Pass each item to lua as a pointer by the index
This removes quite a bit of the work that is needed to get the data into
lua as a table. We are first removing the loop that will join the
results vector into one string. Then we will remove the copy of this
string into lua. We will then finally remove the loop to split the
string and create a table from it in lua. All of this ends up in a 12%
speed up.
Output for ./scripts/bench 0.x
Benchmark 1: HEAD
Time (mean ± σ): 2.667 s ± 0.065 s [User: 8.537 s, System: 1.420 s] Range (min … max): 2.588 s … 2.767 s 10 runs
Benchmark 2: 0.x
Time (mean ± σ): 2.337 s ± 0.150 s [User: 9.564 s, System: 1.648 s] Range (min … max): 2.161 s … 2.529 s 10 runs
Summary
HEAD ran 1.14 ± 0.08 times faster than 0.x