3 ms·
Seeing this, I wonder if it is possible to optimize the bytecode. E.g. in the last example you could inline bb3: and remove the STORE_FAST/LOAD_FAST pair twice
by hyperman1 5y ago
Seeing this, I wonder if it is possible to optimize the bytecode. E.g. in the last example you could inline bb3: and remove the STORE_FAST/LOAD_FAST pair twice.
Bytecode might get a bit faster and maybe smaller, but probably not enough to make it worth it, assuming the python interpreting is not the bottleneck of your code. You presumably can't do much advanced optimization like inlining, as python is potentially very dynamic with lots of reflection.
- tekknolagi 5y agoIt's definitely possible to optimize the bytecode. For example, I am working on another post right now that adds definite assignment analysis. It imagines an opcode LOAD_FAST_UNCHECKED that elides the runtime null check, and then replaces all definitely-assigned LOAD_FASTs with that. Regarding inlining: if you have the right data structures, inlining is possible. For example, I add an inliner to our Python JIT here: https://github.com/facebookincubator/cinder/commit/f3c50b3938906149b32c9cd36c3a41f0e898b52d https://github.com/facebookincubator/cinder/commit/f3c50b393... The SSA IR makes this reasonably straightforward. The harder part was runtime frame reflection and keeping stack traces consistent (pretending like nothing was inlined).
- hyperman1 5y agoI should have known, this is stack overflow after all. You're working on tech that successfully does exactly what I just declared undoable. Cinder looks very interesting. I have quite a lot of questions, but it looks like your readme answers a lot of them, so I'll spend the evening reading it first. My hat off to you.
- tekknolagi 5y agoLet me know what questions you have! We're working on this stuff in the open but it's not always easy to see the bigger picture of what's being worked on. Also, I think it's not necessarily required to have a JIT but I'll have to take a look at https://dl.acm.org/doi/10.1145/1534530.1534550 https://dl.acm.org/doi/10.1145/1534530.1534550 again to see if they handle a lot of the corner cases properly
- anamax 5y agoIt's not clear how that handles local functions that are redefined or that have multiple definition sites.
- rurban 5y agoWhy a these TODO(emacs)? Is there a special emacs ticket or tool?
- tekknolagi 5y agoHaha, that's my internal username at work. emacs is a nickname I got in college. EDIT: Actually, where are you seeing this? I don't see any in the blog post. Is it Skybison? EDIT 2: Oh, the Cinder commit. Yep.
- masklinn 5y ago> You presumably can't do much advanced optimization like inlining, as python is potentially very dynamic with lots of reflection. You need a JIT, such that you can deoptimise and possibly reinline: any function referred to could be modified at rutime. Technically even local variable could be modified by one of the callees reaching back through the callstack, the cpython runtime structure is documented and code does leverage it. So pypy can do it (and often it means dynamic trickery and reflection is quite expensive there).