Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Julia does it an order of magnitude better, though.

A generic `f` will probably be similar to the Common Lisp one. However, as soon as you use `f` in a context where types are known (e.g. if you use multimethods to overload a function that calls `f`), it will be specialized and JIT-compiled for the specific type (int, float, matrix, ...), with no extra work for the programmer.



In the 'Lisp World' JIT compiler are mostly not used. The main approaches are:

* program compilation, where the object system can declare parts as non-extensible

* a runtime compiler, which can compile methods

See for example for a recent attempt to statically compile methods and handing the types to the optimizing compiler (which also uses type inference):

https://github.com/guicho271828/inlined-generic-function/


In the Lisp World, Racket has a great JIT which is optional. https://docs.racket-lang.org/guide/performance.html

Racket is a beautiful thing.


Racket is Racket.

CLISP also can use a JIT - it uses GNU Lightning for runtime native code generation (https://www.gnu.org/software/lightning/).

Anyway the Racket JIT seems to be a bit limited:

> The JIT compiler works incrementally as functions are applied, but the JIT compiler makes only limited use of run-time information when compiling procedures, since the code for a given module body or lambda abstraction is compiled only once. The JIT’s granularity of compilation is a single procedure body, not counting the bodies of any lexically nested procedures.


If I understand correctly, functions are inlined[0] (not saying this is bad, just different). If you declare functions as inline then you can get rid of the dispatching code in contexts where the type is known in advance.

[0] https://github.com/JuliaLang/julia/issues/265


Yes, small and explicitly tagged functions can inline directly into the caller. But even when that doesn't occur, Julia is able to avoid dynamic dispatch overhead by doing the dispatch at compile-time, making the function call point directly at the specialized method.


In order to do that with CLOS, we have to add an explicit "inline" directive (as shown by lispm in another comment), because methods can be redefined anytime. Taking a shortcut to an effective method could break the code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: