PHP 8.6 Closure Optimizations
2 days ago
- #PHP
- #closures
- #optimization
- Proposes two optimizations for closures in PHP 8.6: static closure inference and stateless closure caching.
- Static closure inference turns non-static closures into static ones if they don't use $this, reducing reference cycles and improving garbage collection.
- Stateless closure caching reuses identical closures that are static, capture no variables, and declare no static variables, improving performance.
- Backward compatibility considerations include changes in ReflectionFunction::getClosureThis() behavior, identical closures from the same lexical location, and earlier object destruction.
- The RFC was accepted, with voting showing strong support (44 yes, 1 no).