Does this optimization make any sense? Is it a good idea?
Hi, I'm building a PHP interpreter in Rust. I still have a lot to implement, but while coding, I had an idea and I'm unsure if it exists in this kind of scenario. I’d love to hear your opinions.
After generating the entire AST (Abstract Syntax Tree), I was thinking about adding an additional step before executing the instructions. This step would involve iterating over the AST to generate an optimized version. Here are a couple of optimizations I had in mind:
- If the system detects that a variable is used only once, it could suggest avoiding cloning the value, and instead, directly move it to where it’s needed.
- If a function is called more than once, it could suggest that after the first call, the function’s body (i.e., the statements generated by the AST) be copied for reuse.
These are just some ideas. Do they make sense? Is it a good approach? I'm fairly new to interpreter development, so I would appreciate your feedback. :)