Memoize ExprHandler dispatch in MutatingScope::resolveType()#6040
Conversation
resolveType() re-scanned every tagged handler with a linear supports() sweep on each call - 2.3M supports() calls for 56K dispatches measured on a small self-analysis slice. NodeScopeResolver and TypeSpecifier already memoized this dispatch by Expr class in private copies; extract the memo into a shared ExprHandlerRegistry and use it in all three places.
resolveType() re-scanned every tagged handler with a linear supports() sweep on each call - 2.3M supports() calls for 56K dispatches measured on a small self-analysis slice. NodeScopeResolver and TypeSpecifier already memoized this dispatch by Expr class in private copies; extract the memo into a shared ExprHandlerRegistry and use it in all three places.
|
I have a different version in the turbo-ext PR. Please take a look (it uses WeakMap) as I want to merge it soon. If yours performed better it could be merged first but otherwise I'd prefer the other one. |
|
best of 3 runs: no weakmap with weakmap I don't think the weakmap makes a consistent meaningful difference in my benchmark. I run my benchmark only on in case we are fine in not using weakmap, we should revert the last commit in this PR before merging |
| $cacheKey = get_class($expr); | ||
| if ($expr instanceof Expr\CallLike) { | ||
| $cacheKey .= '|' . $expr->isFirstClassCallable(); | ||
| if ($expr instanceof Expr\New_) { | ||
| $cacheKey .= '|' . get_class($expr->class); | ||
| } | ||
| } |
There was a problem hiding this comment.
diff of my impl vs. native acceleration PR: I made the key unique enough so it can also cache CallLike
|
Yeah, please merge your no-WeakMap version (here), I'll rework the turbo-ext. |
This reverts commit 84c3095.
ExprHandler dispatch in MutatingScope::resolveType()
resolveType() re-scanned every tagged handler with a linear supports() sweep on each call - 2.3M supports() calls for 56K dispatches measured on a small self-analysis slice. NodeScopeResolver and TypeSpecifier already memoized this dispatch by Expr class in private copies; extract the memo into a shared ExprHandlerRegistry and use it in all three places.
before this PR:
after this PR: