In this advanced technique, the author delves into the concept of dynamic code generation, known as codegen, which was common in many programming languages up until the 1980s. The article provides a detailed breakdown of when and how to use this technique to enhance performance, with a real-world example from the author’s work at Humu. The author warns about the complexity and potential for bugs when hand-rolling bytecode in languages like Python, but emphasizes the significant speed improvements that can be achieved when done correctly. This approach, while nuanced and challenging, can be a powerful tool for optimizing code performance.
https://medium.com/@yonatanzunger/advanced-python-achieving-high-performance-with-code-generation-796b177ec79