logoalt Hacker News

PHP 8.6 Closure Optimizations

34 pointsby moebrownelast Tuesday at 10:59 AM4 commentsview on HN

Comments

kevincoxtoday at 12:56 PM

It is an interesting comparison that JavaScript always ensures that different evaluations of a closure expression results in unique instances. So in general the closures will require allocations for each (unless the allocation is otherwise prevented such as via escape analysis). Of course much of the underlying data may be shared, but the identity itself will be unique.

I don't know how strict JavaScript garbage collection rules are. This was non-observable for the longest time but FinalizationRegistry now exists which makes cleanup observable. It sounds like basically no guarantees are provided when an object will be cleaned up, so presumably an implementation would be allowed to make optimizations such are proposed where for PHP.

moebrownelast Tuesday at 10:59 AM

> Non-static closures are turned into static ones if they are guaranteed not to make use of $this.

> Stateless closures, i.e. those that are static, don't capture any variables and don't declare any static variables, are cached between uses.

hyperionultratoday at 12:32 PM

~3% performance gains. I didn’t understood part about $this.

show 1 reply