masak / bel

An interpreter for Bel, Paul Graham's Lisp language
GNU General Public License v3.0
27 stars 1 forks source link

Speed up character and string comparison #333

Closed masak closed 3 years ago

masak commented 3 years ago

In t/comfns.t and t/example-bel.t, some evaluations are commented out simply because comparing characters takes forever.

Would inserting the appropriate fastfuncs help speed it up, so that we can un-TODO those? I think so.

masak commented 3 years ago

About a test such as this one:

ok 3 - "TODO (< \\a \\c) ==> t" ==> "TODO (< \\a \\c) ==> t"

When I run this in the REPL, it takes forever.

But when I run the first two of these, they are almost immediate, and the last one only gives a small delay:

Language::Bel 0.56 -- msys.
> (charn \a)
97
> (charn \c)
99
> (< 97 99)
t

More mysteriously, (bin< \a \c) also takes forever, but (find [all (car _) '(\a \c)] comfns) is fairly immediate. Not really sure what is going on in bin<.

masak commented 3 years ago

Seems I don't have a test file for bin<, go figure.

This issue is quite strongly related to #339, now that I read both of them.

masak commented 3 years ago

Not really sure what is going on in bin<.

It would seem it ends up calling charn, but in such a way that it calls the slow Bel-function version, and not the fastfunc. Now the question is why that happens.

masak commented 3 years ago

I found out why.

I'm somewhat hopeful that there would still be a way to do the right thing with the evaluation, while also preserving the connection with the fastfunc. Even if there isn't a straightforward way to do that, there might be a hacky hard-coded way to do it.