REDUCE/into and COMPOSE/into
When building large block series, it is very common to write:
repend series [a b c]
Which is shorthand for:
append series reduce [a b c]
The evaluated results of a, b, and c are appended to the series.
If this is done a lot, a large number of temporary series are generated, which take memory and also must be garbage collected later.
An optimizing refinement in reduce and compose have been added to the A55 release:
reduce/into [a b c] tail series
compose/into [a (b) c] tail series
These require no intermediate storage.
The savings can be seen if you do:
series: make block! 30000
repeat n 10000 [append series reduce [n + 1 n - 2 n * 3]]
Now, replace the repeat line with:
repeat n 10000 [reduce/into [n + 1 n - 2 n * 3] tail series]
You will see the savings of 10000 block allocations.
Many thanks to Brian Hawley for lobbying for this refinement in R3.