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.
- Strongtalk from the 1990s
- Pharo Smalltalk (Cog VM)
Also worth looking at
- Chez Scheme
And
- JavaScript in every popular modern browser.
And
- Luajit
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.
Python is something like 40 times slower than C, lisp gets much closer with something like 4 times slower (all of this heavily depends on what you are doing obviously, so just rough ballparks here).
Whereas Python has tons of libraries, millions of programmers, tons of support, tons of documentation and books, and billions of lines of existing codebases...
Python was like that once, too. Now we have the necessary experience to understand what are crucial aspects of the language that are missing but are extremely difficult to change post-factum, such as removing the GIL. Nim has no such constraints, and while building the ecosystem takes time, I have no doubts it will progress smoothly as Nim is such a pleasure to use. Even for such a young language I feel we're already in a good shape: https://github.com/nim-lang/Nim/wiki/Curated-Packages.
Also, do you really think the Python team should just give up on performance just because faster languages exist?
Should Tesla stop building cars as soon as someone builds a faster car than them?
nimpy https://github.com/yglukhov/nimpy PyGotham talk: https://www.youtube.com/watch?v=IVgNVJdizHg another blog post: https://robert-mcdermott.gitlab.io/posts/speeding-up-python-...
Nim wants to be its own thing, and posters are quick to point out that Nim isn't Python, never was intended to be, and never will be. That's what the DFL wants, which is fine. But IMO, creating a language that is closely-related to Python, arguably one of the world's most popular languages, and allows / encourages porting large Python codebases, seems like a pretty worth goal. Now that Nim has already made a lot of decisions to make that difficult, it can't pivot to that goal without breaking all the existing Nim code. Too bad: seems like a big opportunity lost to me.
well they do state "copying bad design is not good design" in the main page. Actually porting Python code to Nim is not that difficult especially when people care enough to create pages like: https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programm...
I think it's best to accept Python is just slow, and to use another language.
Oh wait, achieving native speed is close to impossible for a dynamically-typed language.