cpu time: 16336 real time: 16416 gc time: 2497
cpu time: 13286 real time: 13332 gc time: 573
cpu time: 515 real time: 517 gc time: 255
Currently, both for/treelist and treelist-reverse are implemented using
iterative element insertion. For example, for/treelist relies on for/fold
and treelist-add. Could these operations be re-implemented to take advantage
of vectors for more efficient execution? For example, re-implement for/treelist
using for/vector and vector->treelist.
On the other hand, My library requires functions like vector-reverse! and vector-shuffle!. These functions are currently not provided in racket/vector
but could be used to implement other operations, such as treelist-reverse, treelist-shuffle, and shuffle. I plan to open a new PR to provide these vector
functions. I recall that Racket prefers not to include treelist-shuffle in racket/treelist. If I create a PR for vector-shuffle!, should it belong in a
separate module (e.g., a shuffle-related module)?
Thank you for the information and suggestions! I wasn't aware of vector-reverse! in srfi/43 or vector-shuffle! in your soup-lib package—both look very useful.
Measuring this a bit more directly, it looks like using for/vector and vector->treelist is consistently faster than using for/treelist directly, and so an implementation revision is probably a good idea.
The internal state used by for/vector can be exposed by continuations. I don't think for/treelist should be stateful in that sense.
Most programs create short lists. Lists of length 0, 1, and 2 are especially common, and for forms are used on short lists all the time. Lists of length 1000000 or 10000000 are rare. A performance argument needs to take short lists into account.