You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL:DR: Determine fast path in getKeyPropertyName() by the count of non-primitives in unions, not just the length of unions.
I'm investigating type check / vscode completion performance issue with material-ui v5, and found this one of root causes.
(See mui/material-ui#19113 (comment) for more detail of the investigation.)
getKeyPropertyName() is (indirectly) called from chooseOverload() to determine argument type matches to the method signature. It has fast path (that returns undefined) for small union with less than 10 constituents.
Currently it checks only one of: "length of union" OR "existence of non-primitive":
While I'm not tested with emotion itself, both are using almost the same type. Profiler result of getDiagnostics() when editing the file contains styled() call of material-ui v5 (with some optimization) will looks like this:
This is because they have 10-12 constitutions in the union.
Removing 3 items from InterpolationPrimitive will remove getKeyPropertyName() entry from above profiler result and improves performance (In above environment 170-210ms to <= 20ms).
But it'll break library feature.
So, in getKeyPropertyName(), count non-primitive constitutions instead of length can improve performance for primitives-rich unions.
π Motivating Example
Improves type check performance when you have large union with many primitives.
π» Use Cases
See above.
The text was updated successfully, but these errors were encountered:
There seems no change on perf suites, it may be nice to have an editing scenario performance test..!
(I could not find perf suites source code on GitHub. Is it a private repo?)
For later reference, this is rough benchmark result for adding/removing extra line break in this file with vscode on my machine:
Suggestion
π Search Terms
performance
emotion
material-ui
getKeyPropertyName
chooseOverload
instantiation
instantiate
large union
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
TL:DR: Determine fast path in
getKeyPropertyName()
by the count of non-primitives in unions, not just the length of unions.I'm investigating type check / vscode completion performance issue with material-ui v5, and found this one of root causes.
(See mui/material-ui#19113 (comment) for more detail of the investigation.)
getKeyPropertyName()
is (indirectly) called fromchooseOverload()
to determine argument type matches to the method signature. It has fast path (that returnsundefined
) for small union with less than 10 constituents.Currently it checks only one of: "length of union" OR "existence of non-primitive":
This causes eager instantiation of large union type with many primitives + few non-primitives. For example it affects material-ui v5 (mui/material-ui#19113 (comment)) and emotion (emotion-js/emotion#2257).
While I'm not tested with emotion itself, both are using almost the same type. Profiler result of getDiagnostics() when editing the file contains
styled()
call of material-ui v5 (with some optimization) will looks like this:This is because they have 10-12 constitutions in the union.
https://github.com/emotion-js/emotion/blob/f3c51e8aca287170e43110bee2e4527eacfcada4/packages/serialize/types/index.d.ts#L20-L29
Removing 3 items from
InterpolationPrimitive
will removegetKeyPropertyName()
entry from above profiler result and improves performance (In above environment 170-210ms to <= 20ms).But it'll break library feature.
So, in
getKeyPropertyName()
, count non-primitive constitutions instead of length can improve performance for primitives-rich unions.π Motivating Example
Improves type check performance when you have large union with many primitives.
π» Use Cases
See above.
The text was updated successfully, but these errors were encountered: