random-state.net

Curios, oddities, vagaries and anomalies -- all to amuse the old and delight the young. Lisp hacks sold during intermission.

files/  images/  tmp/  pubkey.asc  rss.xml

Log

...more at Flickr

Holiday Hack: Bit Position #
hacking, December 30th 2011

Logically speaking, POSITION with trivial :KEY and :TEST arguments should be much faster on bit-vectors than on simple vectors: the system should be able to pull one words worth of bits out of the vector at a single go, check if any are set (or unset), and if so locate the one we're interested in — else going on to grab the next word.

Practically speaking, no-one who needed fast POSITION on bit-vectors seems to have cared enough to implement it, and so until yesterday (1.0.54.101) SBCL painstakingly pulled things one bit at a time from the vector, creating a lot of unnecessary memory traffic and branches.

How much of a difference does this make? I think the technical term is "quite a bit of a difference." See here for the benchmark results. First chart is from the new implementation, second from the new one. Other calls to POSITION are included for comparison: ones prefixed with generic- all go through the full generic POSITION, while the others know the type of the sequence at the call-site, and are able to sidestep a few things.

So, if you at some point considered using bit-vectors, but decided against them because POSITION wasn't up to snuff, now might be a good time to revisit that decision.

Gory details at the end of src/code/bit-bash.lisp, full story (including how the system dispatches to the specialized version) best read from git.

Also, if you're looking for an SBCL project for next year, consider the following:

  • Using a similar strategy for POSITION on base-strings: on a 64-bit system one memory read will net you 8 base-chars.
  • Using similar strategy for POSITION on all vectors with element-type width of half-word or less.
  • Improving the performance of the generic POSITION for other cases, using eg. specialized out-of-line versions.

Happy Hacking and New Year!

Filthy Lucre

I have a one-man company called Steel Bank Studio that provides commercial SBCL support and Common Lisp consulting in general. If you need a Common Lisp or SBCL expert for hire, get in touch.

I also sell some Lisp and SBCL merchandise on CafePress: around 50% of the sales price goes towards funding my work on SBCL.

If you wish, you can also directly donate money using the button below. Anything you wish to give is much appreciated, but nothing is required or expected.

You can also subscribe to my email newsletter—at the price of your choosing. Please understand that this is little more than a mechanism for recurring donations: while I try to make sure there's something interesting on a monthly basis at least, I make no promises regarding the frequency or contents of the newsletter.

Subscription options
Email address

Thanks for your support, and Happy Hacking!

 — Nikodemus Siivola

Nikodemus Siivola, <nikodemus@random-state.net>
Vaasankatu 6 C 49, 00500 Helsinki, Finland
+358 44 2727 526

Why Common Lisp?

Read all about the features of Common Lisp.

Projects

I'm involved in more open source projects than I care to count. Here are the ones I think need more googlejuice.

Recommendations

If you are looking for lisp libraries, use Quicklisp and look no further.

Life

I practise historical fencing at School of European Swordmanship Helsinki, and keep a separate training diary about that.

...I do other stuff as well, but that's none of your business. :)

Creative Commons License Unless otherwise noted, contents of this website are licensed under a Creative Commons Attribution 2.5 License.