-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flow][perf] Almost disjoint union optimization
Summary: Why am I doing this? [Hermes ESTree types](https://github.com/facebook/hermes/blob/main/tools/hermes-parser/js/hermes-estree/src/types.js) has almost disjoint union and it's very hard to change (we can't really change ESTree), and it's very slow to check. With this change, the ones in hermes-parser repo is still not optimized yet, since they use interfaces, but at least we are much closer. In this diff, we start track the currently failing cases of disjoint union optimizations due to non-unique keys, and we group them together. Therefore, given the following union: ``` type Node = {type: 'lit', subType: 1} | {type: 'lit', subType: 2} | {type: '+', e1: Node, e2: Node} | {type: '-', e1: Node, e2: Node} ``` the grouping will be: ``` type: { 'lit' => {type: 'lit', subType: 1}, {type: 'lit', subType: 2} '+' => {type: '+', e1: Node, e2: Node} '-' => {type: '-', e1: Node, e2: Node} } ``` When there are only one item in the bucket, the usual optimization will apply and we are in a happy path. When it's not, then we will emit `Unknown` as the member test result, but we only pay the extra cost proportional to the number of non-unique keys. We don't see a significant change in perf number, probably because such code that will can benefit from this optimization is either too small, or already impossible to land. However, I think the infrastructure built in this diff can still be helpful for other purposes. e.g. consider ``` const node: Node = { type: '+', e1, // still typing e2 } ``` right now we generate a big error with all the branches, but perhaps we can use the information to only show that it's incompatible with plus node. In addition to this optimization, I still keep this case as an error with `$Flow$EnforceOptimize`, but give it a different error code. The infra built in this diff also allows us to show all the non-unique keys at once, instead of the first one we find. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D54650850 fbshipit-source-id: 67e084a098e4c2675eeecb654568b4075345956d
- Loading branch information
1 parent
5a25199
commit 5523408
Showing
9 changed files
with
206 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[options] | ||
all=true | ||
casting_syntax=both |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Found 0 errors |
Oops, something went wrong.