I tried writing a bytecode optimizer a few months ago, and actually got some basic inlining and constant propagation and other such optimizations working, but then realized it's gonna be fairly useless since bytecode changes between Python versions and isn't necessarily even going to be consistent across different Python implementations. So I abandoned that project and started working on an AST-based optimizer. Sadly I actually deleted that project (which is otherwise not something I normally do) as a means to get myself to stop sinking more time into it, but now that means I still have to mentally figure out some of the techniques I came up with again if I want the AST-based version to go anywhere...