-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
perf: improve typescript type checking performance #10515
Conversation
I have a related question. Is it actually ok to allow strings for object ids in query filters? In my experience trying to query something as a string when it's stored as an Are the types actually correct in trying to allow strings for object ids for filters here? |
my system specifications are:
before applying changes in the PR #10515
after applying changes in the PR #10515
|
@perenSHERE the check time itself is not necessarily conclusive to VS code performance. But it's a decent indicator to check whether changes are for the better or worse. Did you try this in VS code? |
Some major changes are needed in the
|
If I leave all the code in updateOne(filter?: FilterQuery<T>, update?: UpdateQuery<T> | UpdateWithAggregationPipeline, options?: QueryOptions | null, callback?: (err: CallbackError, res: any) => void): QueryWithHelpers<UpdateWriteOpResult, EnforceDocument<T, TMethods>, TQueryHelpers, T>; If I remove its return type, the check time goes down to Alternatively, if everything is kept but the code of So the problem isn't in the |
Update: Changing the definition of class Schema<DocType = Document, M = Model<any, any, any>, SchemaDefinitionType = undefined, TInstanceMethods = any> extends events.EventEmitter { Results in this trace.
It appears that one potential problem is with the |
I have opened microsoft/TypeScript#45249, perhaps someone can offer some guidance. |
Definitely commit this to the branch dropped the Total Time Decently for me I am not that experienced with type declaration but after reading some code Model Interface can be optimized decently |
Just to be sure how optimized the types can be I deleted every package I had and took the bare minimum to launch the project. The only package I had was typescript
I got my time dropped to |
Re: "Is it actually ok to allow strings for object ids in query filters?", yes it is. |
I suspect the solution will be removing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange that this improves perf so much, but it passes our tests so should be fine 👍
@vkarpov15 Changing it to: I think the type is valuable though, so removing it may not be a good idea. The underlying problem is related to a high level of recursivity that the typescript compiler goes into to verify the If a solution is found there, then A very simple way to play with this is via: https://github.com/andreialecu/typescript-performance-extends Just edit the |
Some more changes are needed so opening a new PR with some more fixes and stopping the recursion is necessary |
Summary
Related #10349
You can use the repro at https://github.com/andreialecu/repro-mongoose-slow-ts
Output of
yarn tsc --extendedDiagnostics
.Before:
After:
Notice a huge decrease in
types
andinstantiations
, and also inCheck time
.I'm not sure if this is the right change, but there was some overlap with
_AllowStringsForIds
being used byDocumentDefinition
doing most of the same work as_FilterQuery
is doing. That seems unnecessary and theDocumentDefinition<T>
seems like could be applied to just a specific part of the type.This doesn't seem to break anything in my code base, and I got most of the speed back.