REBOL 3.0

REDUCE/into and COMPOSE/into

Carl Sassenrath, CTO
REBOL Technologies
27-May-2009 23:44 GMT

Article #0208
Main page || Index || Prior Article [0207] || Next Article [0209] || 9 Comments || Send feedback

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:

recycle
stats/show
series: make block! 30000
repeat n 10000 [append series reduce [n + 1 n - 2 n * 3]]
stats/show

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.

9 Comments

REBOL 3.0
Updated 25-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net