4 ms·
Yes, definitely. Python is much much more dynamic than Javascript -- the jump in dynamicness of Javascript to Python is about equivalent to Java to Javascript,
by kmod 5y ago
Yes, definitely. Python is much much more dynamic than Javascript -- the jump in dynamicness of Javascript to Python is about equivalent to Java to Javascript, and similarly requires a different set of techniques.
The single example I typically give is that in Python you can inspect stack frames after they've exited! This has concrete implications on your VM design.
Another example is that the multiple dispatch protocol for binary operations (such as addition) is sufficiently complicated that you generally cannot encode it into your compiler. We have been able to have a simplified version of that by building a tracing JIT for C, which is able to understand the dispatch protocol, but it is not always applicable.
Source: I've been working on Python optimization for several years as part of the Pyston project.
- pjmlp 5y agoNot more dynamic than Smalltalk or SELF, though.
- anticensor 5y agoUnlike JavaScript however, Python is strongly typed.
- IshKebab 5y agoPython's type system is not more strongly typed than JavaScript's in any way that makes it easier to optimise.
- Spivak 5y agoYeah but in practice basically all JS code in the wild is strongly typed since the community has long since decided that relying on implicit type coercion is a massive footgun. Also I think Python’s truthy/falsey semantics make it dangerously close to being weakly typed.
- staticassertion 5y agoAll that means is that you get more exceptions raised when you use ==. It doesn't help performance at all, it doesn't even really confer anything about types, only that __eq__ is implemented between fewer types.
- anticensor 5y agoPython exceptions are low-cost. It has to be that way because every for loop in Python throws an exception.
- iqanq 5y ago>The single example I typically give is that in Python you can inspect stack frames after they've exited! This has concrete implications on your VM design. How about an implementation of python that doesn't let you do fancy things like that that are not needed in production?
- Jasper_ 5y agoThe inspecting of stack frames is used by the logging library, and by most unit testing libraries. There are dozens of these small features which are challenging, and if you remove all of the challenging ones, you end up with something where pretty much no existing Python can run. People have tried, pypy started with that goal before it became clear it wasn't practical.
- akx 5y agoI think logging inspects frames while they're still on the stack, not post-fact..?
- ravi-delia 5y agoIs there any reason that Python's dynamicness (dynamicity?) is so much more of a hindrance than CL's? Is it just that CL is compiled?
- robert-brown 5y agoThe end of this post explains why Common Lisp can run much faster than Python. https://markmail.org/message/dp56i26zhpf4fehb#query:+page:1+mid:vxgbk5z7gipau2ah+state:results https://markmail.org/message/dp56i26zhpf4fehb#query:+page:1+...
- frozenport 5y ago>> in Python you can inspect stack frames after they've exited! How does that work and what is it used for?
- kaba0 5y agoDo you happen to know something about the graal python implementation? Based on other comments here, the often used C FFI can also hinder the work of Python implementations, and the graal project solves it by JIT compiling C code as well (from llvm ir) From what I’ve seen last time I heard about graal python is that it is seldom faster than the pypy approach (AST-based vs tracing JIT), even though in case of TruffleRuby and TruffleJS it is insanely fast compared to the maturity of the projects. Is your mentioned example of stack frame inspection make it map much worse to Java primitives (which happens behind the scenes of the truffle languages)?