3 ms·
How can say lisp, a language that touches the heap profusely, be faster than c or rust?
by adamnemecek 6y ago
How can say lisp, a language that touches the heap profusely, be faster than c or rust?
- uryga 6y agoi've heard a lot about SBCL and the efficient machine code it generates. i'm guessing a lot of the heap stuff can be optimized away if the code is written right (e.g. via escape analysis or eliminating intermediate values). though i'm guessing that if you really want the best performance, you just end up writing C/Rust with a lot of parentheses :)
- lisper 6y agoYou have to compare apples and apples. Lisp can "touch the heap profusely" but it doesn't have to. You can trade off programming convenience for heap touching. But GC technology has come a very long way, and GC's optimized for Lisp's particular pattern of heap touching have become exceptionally good. Such technology is now standard equipment in EVERY language EXCEPT C and C++, and even C and C++ have them as bolt-on accessories. For some kinds of tasks, Lisp can actually be faster than C or C++. This is why, for example, the Orbitz search engine was written in Common Lisp.
- adamnemecek 6y agoOK can I see some numbers?
- lisper 6y agoSure. What kind of numbers would you like to see?
- adamnemecek 6y agoThat show that lisp is comparably fast as c.
- kazinator 6y agoThe class of problems you can solve with a C program that doesn't touch the heap profusely is small. C programs that touch the heap profusely often do it in bad ways which are necessary so that they can be debugged to production. For instance, a commonly seen design decision in C programs is to avoid sharing objects, leading to increased memory use, increased calls to malloc and wasteful copying overhead. A Lisp program rarely calls the equivalent of strdup for instance; you don't worry about who is going to free this, and will two modules try to do it to the same object?