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 error reporting in TSX. #26680

Closed
deftomat opened this issue Aug 26, 2018 · 6 comments
Closed

Slow error reporting in TSX. #26680

deftomat opened this issue Aug 26, 2018 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified

Comments

@deftomat
Copy link

deftomat commented Aug 26, 2018

TypeScript Version: 3.1.0-dev.20180825

Search Terms: jsx, performance, slow

Issue
We find out that an error reporting in medium size React project is quite slow, especially in entry component like App.tsx.

For example, our App.tsx contains a lot of routes (react-router v4). These routes are rendering another components, which contains another bunch of routes, etc.

This approach is quite normal as you actually defining a whole application hierarchy in App.tsx. So, basically this entry component is referring to each component in a project.

We find out that error reporting is much slower in App.tsx than in some other component in hierarchy. Here is a simplified code:

// App.tsx
export default function App() {
  return (
    <Fragment>
      <UntrustedLink href="https://www.typescriptlang.org/" />
      <AdminSection />
      ...
    </Fragment>
  );
}

// AdminSection.tsx
export default function AdminSection() {
  return (
    <Fragment>
      <Route path="..." component={Cmp1} />
      <Route path="..." component={Cmp2} />
      ...
    </Fragment>
  );
}

Now, when I do some mistake in App.tsx like changing href="..." to hrefa="...", VSCode fires a request to tsserver and it responds with an error message. However, it took like 2 seconds to complete.

However, if we add a return type to AdminSection function

export default function AdminSection(): any {

then it is much faster and it took like 1 second.

It was measured in simplified code. In our real code, it took like 3 -4 seconds to report a proper error.

This leads me to my question: Is there any caching for unchanged files? Because it looks like TS is trying to infer the return type of a referred function each time I change an App.tsx even when other files didn't change. Providing an explicit return type obviously speed up this process as TS is probably skipping inferring process. Adding more components without explicit return type makes this slower and slower.

I'm not sure if it is related to JSX. Probably not, but it is definitely most noticeable in React apps.

Tested on macOS, Node 10.9, VSCode (insiders), TS 3.0.1 and 3.1.0-dev.20180825.

Possibly related: #25302

TSServer logs (with inferred return types)
Info 1132 [9:44:0.481] request:
{"seq":27,"type":"request","command":"change","arguments":{"insertString":"a","file":"/Users/deftomat/Development/projects/efa-test/src/pages/App.tsx","line":83,"offset":32,"endLine":83,"endOffset":32}}

Info 1155 [9:44:2.413] event:
{"seq":0,"type":"event","event":"semanticDiag","body":{"file":"/Users/deftomat/Development/projects/efa-test/src/pages/App.tsx","diagnostics":[{"start":{"line":83,"offset":14},"end":{"line":83,"offset":27},"text":"Type '{ hrefa: string; }' is not assignable to type 'Props'.\n Property 'href' is missing in type '{ hrefa: string; }'.","code":2322,"category":"error"}]}}

TSServer logs (with explicit return types)
Info 1630 [9:48:10.441] request:
{"seq":127,"type":"request","command":"change","arguments":{"insertString":"a","file":"/Users/deftomat/Development/projects/efa-test/src/pages/App.tsx","line":83,"offset":32,"endLine":83,"endOffset":32}}

Info 1653 [9:48:11.52] event:
{"seq":0,"type":"event","event":"semanticDiag","body":{"file":"/Users/deftomat/Development/projects/efa-test/src/pages/App.tsx","diagnostics":[{"start":{"line":83,"offset":14},"end":{"line":83,"offset":27},"text":"Type '{ hrefa: string; }' is not assignable to type 'Props'.\n Property 'href' is missing in type '{ hrefa: string; }'.","code":2322,"category":"error"}]}}

@deftomat deftomat changed the title Slow error reporting from tsserver in JSX. Slow error reporting from tsserver in TSX. Aug 30, 2018
@deftomat deftomat changed the title Slow error reporting from tsserver in TSX. Slow error reporting from tsserver in TSX. Aug 30, 2018
@deftomat deftomat changed the title Slow error reporting from tsserver in TSX. Slow error reporting from in TSX. Aug 30, 2018
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.2 milestone Sep 7, 2018
@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Sep 7, 2018
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Sep 7, 2018

Perhaps @weswigham can investigate this. We may need more information to diagnose this though. Could you provide a totally self-contained repro so that we can easily see the difference in speed?

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label Sep 7, 2018
@deftomat deftomat changed the title Slow error reporting from in TSX. Slow error reporting in TSX. Sep 7, 2018
@weswigham
Copy link
Member

I'd need a concrete sample to do perf analysis with, otherwise I'd just be guessing. Y'all have a project you can share which exhibits poor performance?

@deftomat
Copy link
Author

deftomat commented Sep 7, 2018

Hi @weswigham
Well, it is a private project. However, I will try to create something, which will reproduce it. Hopefully, this weekend.

@deftomat
Copy link
Author

deftomat commented Sep 11, 2018

@weswigham
Here it is: https://github.com/deftomat/error-reporting-in-tsx.
There is no working build process as I replace everything with bunch of useless components and I throw away most of the tooling.

To test it, you can try to add/remove this line and analyse a time necessary to report the problem.

Then, you can search for all Section() occurrences and replace them with Section(): any.
Now, time to report the problem after add/remove of that line will be much shorter.

Also, it could be related to microsoft/vscode#56909 as intellisense will fire after the successful type-check.

@weswigham
Copy link
Member

@deftomat Thanks! Your repro seriously helped identify where the issue was!

@deftomat
Copy link
Author

deftomat commented Oct 8, 2018

@weswigham
TypeScript is on 🔥🔥🔥.
Thank you for all my colleagues as you speed it up a LOT!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants