Supercharge your Python library using AST parsing
summary
Shows concrete AST rewrites using Python’s stdlib ast plus the Python/C API to turn user node functions into generators that maintain state, replace frequent CSP.tic and CSP.output calls with member-slot ops to avoid attribute lookups, and map C++-side values into the fast locals array so Python loads are cheap. Benchmarks show the slot trick gives about 1.5–2x faster call performance; these transforms power the open‑source CSP runtime and run in production but require upkeep across Python 3.9–3.12.
AI-written summary · about
chapters (8)
- 0:00AST parsing in Python
- 2:53Abstract syntax trees
- 11:04Computation graphs and CSP
- 15:36Functions to generators for state
- 18:01Optimizing member calls with AST
- 21:50C++ data as local variables
- 26:28Conclusion
- 27:12Q&A
related talks
36mHacking the Python AST
24mThe AST and Me
17mUnlocking Python's AST: The Metaprogramming Superpower You Didn't Know You Had
25mPython as a Hackable Language for Interactive Data Science
30mDoing stupid things with ASTs
28mSafely eval Python syntax using the AST module
32mWriting performant code for modern Python interpreters
32mCode as Data_ A Practical Introduction to Python’s Abstract Syntax Tree
