Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up TypeScript perf #12284

Merged
merged 3 commits into from
Aug 21, 2022
Merged

Speed up TypeScript perf #12284

merged 3 commits into from
Aug 21, 2022

Conversation

vkarpov15
Copy link
Collaborator

Summary

Fixes up #10349. Before this PR:

$ ./node_modules/.bin/tsc --extendedDiagnostics gh-10349.ts 
Files:                         126
Lines of Library:            27583
Lines of Definitions:        53181
Lines of TypeScript:            20
Lines of JavaScript:             0
Lines of JSON:                   0
Lines of Other:                  0
Nodes of Library:           118533
Nodes of Definitions:       142841
Nodes of TypeScript:            89
Nodes of JavaScript:             0
Nodes of JSON:                   0
Nodes of Other:                  0
Identifiers:                 92346
Symbols:                    177166
Types:                       76289
Instantiations:             334872
Memory used:               204744K
Assignability cache size:    26192
Identity cache size:           175
Subtype cache size:              2
Strict subtype cache size:       4
I/O Read time:               0.01s
Parse time:                  0.55s
ResolveModule time:          0.03s
ResolveTypeReference time:   0.00s
Program time:                0.62s
Bind time:                   0.24s
Check time:                  2.62s
transformTime time:          0.01s
commentTime time:            0.00s
I/O Write time:              0.00s
printTime time:              0.01s
Emit time:                   0.01s
Total time:                  3.50s

After this PR:

$ ./node_modules/.bin/tsc --extendedDiagnostics gh-10349.ts 
Files:                         126
Lines of Library:            27583
Lines of Definitions:        53167
Lines of TypeScript:            20
Lines of JavaScript:             0
Lines of JSON:                   0
Lines of Other:                  0
Nodes of Library:           118533
Nodes of Definitions:       142530
Nodes of TypeScript:            89
Nodes of JavaScript:             0
Nodes of JSON:                   0
Nodes of Other:                  0
Identifiers:                 92229
Symbols:                    101736
Types:                       47377
Instantiations:              75893
Memory used:               166417K
Assignability cache size:    17401
Identity cache size:           171
Subtype cache size:              2
Strict subtype cache size:       4
I/O Read time:               0.05s
Parse time:                  0.53s
ResolveModule time:          0.03s
ResolveTypeReference time:   0.02s
Program time:                0.66s
Bind time:                   0.23s
Check time:                  1.80s
transformTime time:          0.01s
commentTime time:            0.00s
I/O Write time:              0.00s
printTime time:              0.01s
Emit time:                   0.01s
Total time:                  2.70s

We're mostly undoing some more changes from #11650: typing exists<>, etc. based on schema is pretty slow. But most of the performance impact, oddly enough, came from adding extends Query in Schema.pre() and Schema.post(). Removing that has brought us back to the perf we had back in 6.3.0 👍

Examples

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks 👍

@kachkaev
Copy link

kachkaev commented Sep 1, 2022

This line broke typings in a project I help maintain:

toConstructor(): typeof this;

That project uses typescript 4.1.3, which is quite dated. When dependabot bumped mongoose from 6.2.0 to 6.5.4, CI broke with this error:

node_modules/mongoose/types/query.d.ts:619:29 - error TS2304: Cannot find name 'this'.

619     toConstructor(): typeof this;
                                ~~~~


Found 1 error.

error Command failed with exit code 2

I tried bumping typescript, but it was not very successful. Versions below 4.4 showed the same error and v4.4+ generated a lot of other errors, unrelated to the library. Most of them were to do with error becoming unknown instead of any in catch.

Not sure if this is actionable, but flagging the problem just in case.

@dawidurbanski
Copy link

Just putting it here to let you know this update helped a lot with performance in one very big real project I develop using mongoose. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants