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

Slow IntelliSense with react-hook-form resolvers on commands completionInfo, completionEntryDetails, and, encodedSemanticClassifications-full #46726

Open
JSin opened this issue Nov 8, 2021 · 5 comments
Labels
Domain: Performance Reports of unusually slow behavior Needs Investigation This issue needs a team member to investigate its status.

Comments

@JSin
Copy link

JSin commented Nov 8, 2021

Bug Report

When adding react-hook-form with their resolver library and zod, the IntelliSense time blows up on three commands: completionInfo, completionEntryDetails, and, encodedSemanticClassifications-full.

Before adding the resolver the logs output:

Info 139  [22:19:17.358] getCompletionData: Get current token: 0.021499991416931152
Info 140  [22:19:17.358] getCompletionData: Is inside comment: 0.057999998331069946
Info 141  [22:19:17.358] getCompletionData: Get previous token: 0.05949999392032623
Info 142  [22:19:17.358] getCompletionsAtPosition: isCompletionListBlocker: 0.26919999718666077
Info 143  [22:19:17.369] getExportInfoMap: cache miss or empty; calculating new results
Info 144  [22:19:17.382] getExportInfoMap: done in 19.083700001239777 ms
Info 145  [22:19:17.394] collectAutoImports: resolved 4 module specifiers, plus 0 ambient and -3 from cache
Info 146  [22:19:17.394] collectAutoImports: response is complete
Info 147  [22:19:17.394] collectAutoImports: 4.513700008392334
Info 148  [22:19:17.394] getCompletionData: Semantic work: 35.378199994564056
Info 149  [22:19:17.413] getCompletionsAtPosition: getCompletionEntriesFromSymbols: 19.212099999189377
Perf 150  [22:19:17.422] 27::completionInfo: elapsed time (in milliseconds) 70.9448

Info 159  [22:19:17.525] getCompletionData: Get current token: 0.03389999270439148
Info 160  [22:19:17.525] getCompletionData: Is inside comment: 0.008000001311302185
Info 161  [22:19:17.526] getCompletionData: Get previous token: 0.07129999995231628
Info 162  [22:19:17.526] getCompletionsAtPosition: isCompletionListBlocker: 0.010899990797042847
Info 163  [22:19:17.528] getCompletionData: Semantic work: 2.452999994158745
Perf 164  [22:19:17.732] 29::completionEntryDetails: elapsed time (in milliseconds) 212.3927

Perf 179  [22:19:17.974] 34::encodedSemanticClassifications-full: elapsed time (in milliseconds) 163.9209

After adding the resolver the logs output:

Info 323  [22:22:49.786] getCompletionData: Get current token: 0.04549999535083771
Info 324  [22:22:49.786] getCompletionData: Is inside comment: 0.009299993515014648
Info 325  [22:22:49.786] getCompletionData: Get previous token: 0.12800000607967377
Info 326  [22:22:49.787] getCompletionsAtPosition: isCompletionListBlocker: 0.23919999599456787
Info 327  [22:22:49.803] getExportInfoMap: cache hit
Info 328  [22:22:49.815] collectAutoImports: resolved 7 module specifiers, plus 0 ambient and -38 from cache
Info 329  [22:22:49.815] collectAutoImports: response is complete
Info 330  [22:22:49.815] collectAutoImports: 6.50730000436306
Info 331  [22:22:49.815] getCompletionData: Semantic work: 28.06919999420643
Info 332  [22:22:50.599] getCompletionsAtPosition: getCompletionEntriesFromSymbols: 14.070700004696846
Perf 333  [22:22:50.602] 74::completionInfo: elapsed time (in milliseconds) 822.7960

Info 344  [22:22:50.762] getCompletionData: Get current token: 0.05060000717639923
Info 345  [22:22:50.762] getCompletionData: Is inside comment: 0.010499998927116394
Info 346  [22:22:50.762] getCompletionData: Get previous token: 0.10969999432563782
Info 347  [22:22:50.762] getCompletionsAtPosition: isCompletionListBlocker: 0.008100003004074097
Info 348  [22:22:50.764] getCompletionData: Semantic work: 1.965599998831749
Perf 349  [22:22:51.360] 83::completionEntryDetails: elapsed time (in milliseconds) 598.5825

Perf 444  [22:22:59.443] 108::encodedSemanticClassifications-full: elapsed time (in milliseconds) 670.2304

What seems to be an identical issue was previously reported in a now closed ticket (#44851).

🔎 Search Terms

🕗 Version & Regression Information

As noted in the ticket Typescript 4.3 introduced the regression. When downgrading to Typescript 4.2, I do not see this issue. The issue persists when using the PR (#46429) that closed the previously reported issue (#44851). The PR landed in Typescript 4.5.1-rc.

⏯ Playground Link

Example repo can be found:

https://github.com/JSin/type-resolve-bug

💻 Code

import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod/dist/zod";
import { z } from "zod";

const schema = z.object({
  first: z.string().nonempty(),
  second: z.number().gte(0),
});

const Index = () => {
  /*
    If you were to pass no parameters to useForm, IntelliSense is still quick.
    Once you add the object with the resolver property with a zodResolver... IntelliSense speed blows up.
  */
  const { register } = useForm<z.infer<typeof schema>>({
    resolver: zodResolver(schema),
  });
};

🙁 Actual behavior

Extremely Slow IntelliSense

🙂 Expected behavior

Fast IntelliSense

@JSin JSin changed the title Extremely slow IntelliSense with react-hook-form resolvers on commands completionInfo, completionEntryDetails, and, encodedSemanticClassifications-full Slow IntelliSense with react-hook-form resolvers on commands completionInfo, completionEntryDetails, and, encodedSemanticClassifications-full Nov 8, 2021
@andrewbranch
Copy link
Member

We need to know exactly where you were requesting the completions seen in those logs, and it would also help to know which completion item was highlighted (which is the one details are requested for).

@andrewbranch andrewbranch added the Needs More Info The issue still hasn't been fully clarified label Nov 8, 2021
@JSin
Copy link
Author

JSin commented Nov 8, 2021

In the simplified example above, I was trying to get the completions for register. Below is what I forgot to add to the example above.

...
  const { register } = useForm<z.infer<typeof schema>>({
    resolver: zodResolver(schema),
  });
  register(); // Trying to get the completions for register is what I was seeing in the logs.
};

Below is an picture example of the completion item highlighted:
image

@andrewbranch
Copy link
Member

What’s showing in your screenshot is actually a feature called “signature help,” and that request is not in the logs you shared. I’m guessing this is actually what we’re looking at?

image

I get completions very fast here. Can you give more detailed instructions on exactly what you’re doing step by step that triggers the issue? Does it repro with such slow completions every time?

@JSin
Copy link
Author

JSin commented Nov 8, 2021

Apologies that is my misunderstanding with the commands. The "signature help" perf log is always sub 10 ms so I didn't see it as a culprit.

For completionInfo, the subsequent calls are fast and only the first time was it slow.

completionEntryDetails and encodedSemanticClassifications-full calls are still around 800 ms in the repo (around 150 ms in 4.2.4).

The detailed instructions:

  1. type register or autocomplete to register
  2. type the open bracket (
  3. Wait a bit less than a second for the signature helper to appear.

Exactly what I noticed as the problem was the signature helper above taking a long time to show (4.4.4 could take seconds) which previously in 4.2.4 felt immediate. Honestly 800 ms isn't the end of the world and this issue was greatly improved in 4.5.1-rc. Let me know your thoughts if I am being nitpicky here.

@andrewbranch
Copy link
Member

No, 800ms is pretty bad for completionEntryDetails, it’s worth a look. Thanks!

@andrewbranch andrewbranch added Needs Investigation This issue needs a team member to investigate its status. Domain: Performance Reports of unusually slow behavior and removed Needs More Info The issue still hasn't been fully clarified labels Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Performance Reports of unusually slow behavior Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

2 participants