On Mon, Jul 24, 2017 at 4:40 PM, Jay McCarthy <jay.mccar...@gmail.com> wrote: > On Mon, Jul 24, 2017 at 3:18 PM, Alejandro Sanchez > <hiph...@openmailbox.org> wrote: >>> - I'm curious of the performance. In particular, I would expect that a >>> computed jump in unpack could do you good. Did you try that? >> I haven’t investigated performance yet. As I said, I am new to Racket, this >> is my first time doing anything useful in it, my only previous Scheme >> knowledge was from doing the exercises in SICP and dabbling in Guile a bit. >> What is a computed jump? > > Rather than having a big `cond`, you could look up the function that > does the work in a vector and then call it. IMHO, msgpack was designed > with that in mind, because tags that aren't immediate values are all > nicely ordered. So you'd check the size, subtract a constant, and grab > the appropriate procedure from a constant vector. >
Or you can use `case`. Racket's `case` with densely-distributed fixnum constants (like in your code) will: 1. Use a vector lookup to go from the case label (i.e. the tag value) to the index of the RHS clause. 2. Use an open-coded binary search on the index to get to the code itself. (The technique is described here: http://scheme2006.cs.uchicago.edu/07-clinger.pdf) You might want to define a macro on top of `case`, though, to handle ranges of tags, since `case` doesn't have syntax for that. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.