Hacker News new | ask | show | jobs
by coldtea 1867 days ago
>Oh wait, achieving native speed is close to impossible for a dynamically-typed language.

It's actually quite possible, and depends on the scenario.

A dynamically-typed language can analyse actual runtime type use and specialize function calls with a JIT, for example. It's also possible (and there's work in this area) to keep the specializations around for quick startup in the next runs... (and of course, drop them if they no longer hold).

That's how Javascript is much closer to native than Python - in some cases just 2-3 times slower than C. Lisp did very well too (better than more than a few static languages).

And that's with the extreme meta-programming / reflective behavior (which both Python and Javascript have). With less such, one could make a dynamic typing language that can be trivially JITed to run very close to native.

2 comments

I agree: here are some good examples of fast interactive dynamic languages

- Strongtalk from the 1990s

- Pharo Smalltalk (Cog VM)

Also worth looking at

- Chez Scheme

And

- JavaScript in every popular modern browser.

And

- Luajit

An interesting thing about all those examples are that they’re fairly streamlined languages making it easier to write good accelerators. Even JS only has one prototype system and lots of functions. All in contrast to Python which has a quite complex runtime and accidental complexity in the language design details.
> And that's with the extreme meta-programming / reflective behavior (which both Python and Javascript have)

It would be interesting to see what kinds of speeds a scripting language that is actually well suited for JIT would be able to achieve if it had the same tremendous amount of effort put into optimizing it that Javascript has received.