Optimizing By Treating QUOTED! Items As A Container

There's a cost difference between:

>> data: quote first [a b c]
== 'a

>> data: blockify first [a]
== [a]

Adding a quote level just bumps a number in a byte of a Cell. Whereas making a BLOCK! requires creating a whole Array.

We could conceivably treat QUOTED! as if it were iterable, and the iteration could just give the item minus a quote level:

>> data: quote first [a b c]
== 'a

>> for-each item data [print mold data]
a

This might not be crazy. Cutting an array saves 8 platform pointers (32 bytes on 32-bit platforms and 64 bytes on 64-bit platforms.) It's one less entity for the GC to manage... it improves the locality...

It Would Help UPARSE On Day One

While I'm not sure of all the places that might be able to make use of it, certainly the GLOM operator could use it...

>> accumulator: none

>> result: ...
== 'x

>> glom $accumulator result
== 'x

>> result: ...
== 'y

>> glom $accumulator result
== [x y]

It's definitely a sacrifice of clarity for efficiency. :face_with_diagonal_mouth: But UPARSE needs all the performance help it can get.

Exploiting Ren-C's highly-leverage design is going to be critical to making it perform, and I think this is one of those things worth doing.

2 Likes

So I tried this... BUT there's also code that needs to remove items out of a glommed collection.

MAP-EACH can work, but we're trying to be efficient. :frowning:

It's not a huge problem, but it does mean special-casing the quoted item case and not being able to do it with iteration. :man_shrugging: