3 ms·
At the end of the day, the number of optimizations that even a JIT can do on Python is limited because all variables are boxed (each time the variable is access
by nritchie 3y ago
At the end of the day, the number of optimizations that even a JIT can do on Python is limited because all variables are boxed (each time the variable is accessed the type of the variable needs to be checked because it could change) and then function dispatches must be chosen based on the type of the variable. Without some mechanism to strictly type variables, the number of optimizations will always be limited.
- vanderZwan 3y agoPer the spec all JS values are boxed too (aside from values in TypedArrays). The implementations managed to work their way around that too for the most part.
- johncolanduoni 3y agoCouldn’t you say the same for e.g. JavaScript? The variables aren’t typed there either and prototypes are mutable. I could definitely see things being harder with Python which has a lot of tricky metaprogramming available that other interpreted languages don’t but I don’t think it’s as simple as a lack of explicit types.
- btown 3y agoCan’t the happy path be branch predicted and speculatively executed, though? AFAIK V8 seems to do this: https://web.dev/articles/speed-v8#the_optimizing_compiler https://web.dev/articles/speed-v8#the_optimizing_compiler
- Joker_vD 3y agoIIRC Instagram's flavour of Python had unboxed primitives (if the types were constricted enough).
- make3 3y agojavascript is insanely more optimized but has the same limitations as Python. So there is likely a lot more you can do despite the flexibility, like figure out in hot code what flexibility features are not used, & optimize around that
- crabbone 3y agoDon't worry. Python already has syntactical constructs with mandatory type annotations. I will not be surprised if few years from now those type annotations will become mandatory in other contexts as well.
- deleted 3y ago[deleted]