Closed jpellegrini closed 1 year ago
Yay! :)
Hi @jpellegrini,
Thanks for this PR. I have merged it and modified a bit the generated code. I have added an instruction in the VM for cxr functions. Performances are better (but not a lot, and very less than I expected). The good news is that it permits to have better error messages. For instance,
stklos> (cadadr '(1 (2 . 3)))
**** Error:
cadadr: wrong type of argument `3' for car in (cadadr '(1 (2 . 3)))
I see you have included a new instruction. I thought of doing it, but was afraid of adding too many instructions to the VM.
Anyway, the implementation of the CXR functions looks great now! :)
but was afraid of adding too many instructions to the VM.
Yep. I try to avoid the inclusion of new instructions as far as possible. As I said, I really expected better performances with this new instruction. This was not the case, and I'm a bit disappointed. However, since it permits better error messages, I kept it
1. Inline the
cxr
accessorsCurrently STklos has all
cxr
aliases implemented as procedures:This patch optimizes this, opening their code:
Some timings:
Running the STklos tests seems to become very slightly faster (around 1%, average of 20 repetitions) - probably the speedup isn't great here because the cxr functions are not used that often in libraries, and also because there are slow tests (such as the Unicode tests) that don't use them.
2. Optimize
list-ref
for small constant indicesSince the
cxr
accessors have been optimized, we can use them to optimize some cases in list-ref. For example,list-ref
becomes indeed faster: