
Going Faster with Lisp - foob
http://blog.kingcons.io/posts/Going-Faster-with-Lisp.html
======
_ph_
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
> 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
This 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
Thee SPARC CPU has/had instructions to add tagged integers which show that
this can be nearly as fast as "normal integers"

------
taeric
Am I the only person that noticed the hover on the lisp code blocks? Surprised
me at first. Can't tell if I like the idea or not.

Rather, I know I like the idea. I can't decide if I like the execution. I'm
leaning towards liking it.

~~~
SwellJoe
I kinda want my editor to do that when working with Javascript. Deeply nested
callbacks and Promises bend my brain, and it'd be nice to see where one thing
ends and another begins. It's easy to bounce back and forth between opening
and closing parens/brackets (e.g. % in vim) or have it highlighted, but I
often find myself having to sort of scroll back and forth to sort it out in my
head.

------
flavio81
TL;DR: Very interesting article about improving performance in Common Lisp.
The author has a 6502 CPU emulator and finds out how to improve his assembly
output. Additionally, it shows how the "static" typing facilities of Lisp help
for increasing performance.

------
mamcx
How easy is to embed this? If I wanna make a language and use a lisp as the
"backend" this one is good for this?

~~~
lispm
For embedding either as source or as a shared library there are a bunch of
Common Lisp implementations:

ECL / Embeddable Common-Lisp -> Can build standalone executables and libraries
-> [https://common-lisp.net/project/ecl/main.html](https://common-
lisp.net/project/ecl/main.html)

ABCL / Armed Bear Common Lisp -> Embed Common Lisp into JVM applications ->
[http://abcl.org](http://abcl.org)

Commercial CL implementations like Allegro CL and LispWorks support the
delivery of shared libraries. That way you can compile your CL program to a
shared library.

There are even more options (like WCL, mocl, ...).

~~~
dmichulke
Can you elaborate a bit on the (dis-)advantages of ABCL compared to Clojure?

~~~
lispm
Well, it supports all of Common Lisp incl. the whole numeric tower, Condition
System and CLOS. If you know Common Lisp, it's all there. That means it's
compatible with much of the Lisp literature and thus automatically has a well-
written specification for its core language. It provides an interpreter and a
compiler. One can use it with GNU Emacs / SLIME. ABCL has also more the feel
of what one would expect from Lisp, like an interpreter integrated with a
compiler, useful backtraces, Lisp-like error messages and a Break-Loop REPL
using the condition system. The compiler is written in Lisp. Thus it provides
some more of debugging experience 'we' all love. It has much less users, less
Java specific stuff, etc. It's also a bit slower than the typical native
compiled Common Lisp.

