[racket-dev] An implementation of 'case' based on Clinger's "Rapid Case Dispatch in Scheme"

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Jul 22 16:41:07 EDT 2012

On Sun, Jul 22, 2012 at 3:33 PM, Jon Zeppieri <zeppieri at gmail.com> wrote:
> On Sun, Jul 22, 2012 at 4:15 PM, Robby Findler
> <robby at eecs.northwestern.edu> wrote:
>> I don't have any good guesses as to which files trigger the problem,
>> but you could time 'raco make' to try to hone in specific files. Run
>> 'raco make' once to build all of a file's dependencies (or just have
>> finished a raco setup run) and then delete compiled/file_rkt.zo if
>> file.rkt is the file you want to time and run 'raco make' on it.
>
> Thanks. I'll give that a try.
>
>>
>> But 7-15 seconds seems like it could easily just be because it takes a
>> very small amount of time more per case expression and there are a lot
>> of case expressions.
>
> Right -- and I'm hoping to eliminate, or at least to minimize, that
> very small amount of time.
>
> However, it's possible that I was wrong about the cause of the bold
> time difference. Today I updated my 'case-v3' branch with the changes
> that have been committed to the plt master branch since the two
> diverged, and I separately cloned the current plt master to a
> different directory. (Previously, I had been using a tarball as the
> control.) And I started running the build tests again. That's still
> going on, but so far, the preliminary results are the opposite of the
> ones from the other day. My 'case-v3' branch tends to build slightly
> faster.
>
> Obviously, there are any number of things that can account for the
> build time difference: background processes eating up CPU, physical
> file location on disk, etc. If the numbers continue to come out as
> they are now, I'll just conclude that the build time really isn't
> significantly affected one way or the other.
>
>>
>> Have you considered a hybrid approach where you first count the number
>> of clauses and only use your new implementation when it is above some
>> threshold?
>
> My implementation does something like that; it counts the number of
> constants, rather than the number of clauses. That's what Clinger's
> version does, too, and it's probably very slightly more expensive than
> just counting the clauses, but I doubt the difference is noticeable.
> The syntax-case clause looks like:
>
> [(_ v [(k ...) e1 e2 ...] ... [else x1 x2 ...])
>        (if (< (length (syntax-e #'(k ... ...))) *sequential-threshold*)
>            (syntax/loc stx (let ([tmp v])
>                              (case/sequential tmp [(k ...) e1 e2 ...]
> ... [else x1 x2 ...])))
>            (syntax/loc stx (let ([tmp v])
>                              (case/dispatch   tmp [(k ...) e1 e2 ...]
> ... [else x1 x2 ...]))))]
>
> ... where case/sequential build an if-then-else tree.

Oh right. I probably subconsciously remembered that from reading the
paper and from thence came my suggestion.

If you're really trying to dot your i's and cross your t's, you could
write a script that looks  'case' expressions, find the top 10 files
in terms of expression size or expression count and time them using
raco make.

Robby

Posted on the dev mailing list.