This can happen because rg searches files in parallel, so the order in which it finishes the files can be nondeterministic. If you run with -j1 (single-threaded) then it is deterministic.
To get deterministic output in multi-threaded mode, rg could wait and buffer the output until it can print it in sorted order. This might increase memory usage, and possibly time, though I think the increase would be minor.
In the first case, it's searching in parallel, so I bet the order of results is different each time.
In the second case, rg each > foo2 found results in foo1 and put them in foo2. Then rg each > foo3 found results in foo1 and foo2, and put them in foo3. Etc. That's why the file size increases so quickly.
>In the first case, it's searching in parallel, so I bet the order of results is different.
Aha. Thought that needed the -j flag (it says: default threads: 0 in the cli help).
Could it do anything to put them out in order of "depth" (and directory/file sorting order)?
>In the second case, rg each > foo2 found results in foo1 and put them in foo2. Then rg each > foo3 found results in foo1 and foo2, and put them in foo3. Etc. That's why the file size increases so quickly.