4 ms·
SBCL is a very interesting compiler. I can only encourage anyone, who is interested in Lisp or dynamic languages in general to check it out. It always compiles
by _ph_ 9y ago
SBCL is a very interesting compiler. I can only encourage anyone, who is interested in Lisp or dynamic languages in general to check it out. It always compiles to native code, and as the article has shown, you can see what it compiles to. That gives you direct feedback how good the resulting code is.
By default, SBCL always generates "correct" code. That of course means for a dynamically typed language, that it has to assume any type. Also, for integer operations, it means, still producing a correct result, even if the integers exceed the values which can be represented by machine-sized integers. As a result, the generated code isn't overly impressive in the beginning. But SBCL has very high abilities to reason about the code, including type inferencing. So, when you add a few type declarations, the generated code gets substantially faster, often matching and sometimes even exceeding what GCC produces for C programs.
- flavio81 9y ago> it means, still producing a correct result, even if the integers exceed the values which can be represented by machine-sized integers To clarify for people alien to Common Lisp: In lisp, by default, integer numbers can be as big as they need to. From the Common Lisp Hyperspec, the entry on the integer data type says: An integer is a mathematical integer. There is no limit on the magnitude of an integer.
- infogulch 9y agoThis really is the correct default. If something unexpected happens the better failure case is to be a little slower than expected than giving completely absurd results. Then adding the optional power to constrain the inputs allowing the compiler to use more efficient implementation with those assumptions is awesome.
- renox 9y agoThee SPARC CPU has/had instructions to add tagged integers which show that this can be nearly as fast as "normal integers"
- geokon 9y agoIs the type annotation similar to the one in Racket? I wonder if you can get similar performance
- equalunique 9y ago>Also, for integer operations, it means, still producing a correct result, even if the integers exceed the values which can be represented by machine-sized integers. Is this something that SBCL does better than other Lisps? I wonder if perhaps that would be why XMaxima packages seem to have SBCL as a dependency.
- rurban 9y agoYes, SBCL's type inferencer (called python decades ago) and codegen is the best. Only Stalin, a scheme compiler was better. And the commercial ones are also pretty good.
- equalunique 9y agoThanks @rurban for the insight.