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

perf: prevent requests from being sent to the server when outside Angular context #1180

Merged
merged 1 commit into from
Mar 10, 2021

Conversation

atscott
Copy link
Collaborator

@atscott atscott commented Mar 8, 2021

…gular context

The Angular Language Service extension of vscode has several pieces to
it:

  • The client, which communicates directly with vscode
  • The server, which handles LSP requests over an lsp connection
  • @angular/language-service which provides concrete answers to LS queries

We added an optimization the @angular/language-service which exits early
when a request is outside the Angular context. This prevents unnecessary
Angular analysis of a file when we know from the start that there are no
Angular-specific results at a location.

This commit provides an additional optimization by adding a similar preventing
short-circuit from the client side. This prevents requests from even
being sent to the server when we know there is no Angular information at
a location. This optimization is a necessary addition because the server
can be blocked from processing requests if another one is taking a while
to respond. We found that requests for diagnostics, which are necessary
when opening a new file, block other server requests from being
processed. This commit would prevent that block from happening by never
making the request to the server in the first place.

fixes #1176

@atscott atscott added the ivy Feature / enhancement / bug fix in Ivy label Mar 8, 2021
@atscott atscott requested a review from kyliau March 8, 2021 21:05
@atscott atscott force-pushed the shortcircuitclientfix branch from e723fa4 to fea3d90 Compare March 8, 2021 21:17
@atscott atscott added extension Relates to an issue with the VS Code extension perf Performance issue user XP Issue related to user experience view engine issues that affect View Engine language service only labels Mar 8, 2021
@kyliau kyliau changed the title perf: prevent requests from being sent to the sesrver when outside An… perf: prevent requests from being sent to the server when outside Angular context Mar 8, 2021
.vscode/launch.json Outdated Show resolved Hide resolved
.vscode/launch.json Outdated Show resolved Hide resolved
client/src/client.ts Outdated Show resolved Hide resolved
client/src/embedded_support.ts Outdated Show resolved Hide resolved
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript';
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this requires parsing the whole typescript library, could you please do a quick profiling to see if there's any significant difference in startup time before and after this change?
The startup time can be retrieved by running the command Show running extensions, or if you want in-depth report you can run the command Startup performance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the startup time before appears to be 200-300ms and the startup time now looks like 500-600ms. So 2-3x slower.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've done some experimentation based on the regex in the syntaxes and it seems like something that would be feasible without introducing a dependency on typescript: https://github.com/atscott/vscode-ng-language-service/blob/c1b86ff50dd9b4e8c9b29c4e71127483ee26b0e6/client/src/embedded_support.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, we'll proceed with this change, but note the regression in activation time in the change log.

jasmine.json Outdated Show resolved Hide resolved
client/tsconfig.json Show resolved Hide resolved
client/src/client.ts Outdated Show resolved Hide resolved
@atscott atscott force-pushed the shortcircuitclientfix branch from fea3d90 to 743f109 Compare March 8, 2021 22:58
client/src/client.ts Outdated Show resolved Hide resolved
client/src/client.ts Outdated Show resolved Hide resolved
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as ts from 'typescript';
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, we'll proceed with this change, but note the regression in activation time in the change log.

client/src/embedded_support.ts Outdated Show resolved Hide resolved
client/src/embedded_support.ts Outdated Show resolved Hide resolved
client/src/embedded_support.ts Outdated Show resolved Hide resolved
client/src/embedded_support.ts Outdated Show resolved Hide resolved
client/src/embedded_support.ts Show resolved Hide resolved
@atscott atscott force-pushed the shortcircuitclientfix branch 2 times, most recently from 4966017 to 008fdd4 Compare March 10, 2021 21:22
…gular context

The Angular Language Service extension of vscode has several pieces to
it:

* The client, which communicates directly with vscode
* The server, which handles LSP requests over an lsp connection
* @angular/language-service which provides concrete answers to LS queries

We added an optimization the @angular/language-service which exits early
when a request is outside the Angular context. This prevents unnecessary
Angular analysis of a file when we know from the start that there are no
Angular-specific results at a location.

This commit provides an additional optimization by adding a similar preventing
short-circuit from the client side. This prevents requests from even
being sent to the server when we know there is no Angular information at
a location. This optimization is a necessary addition because the server
can be blocked from processing requests if another one is taking a while
to respond. We found that requests for diagnostics, which are necessary
when opening a new file, block other server requests from being
processed. This commit would prevent that block from happening by never
making the request to the server in the first place.

fixes angular#1176
@atscott atscott force-pushed the shortcircuitclientfix branch from 008fdd4 to f7836eb Compare March 10, 2021 21:23
@atscott atscott merged commit 5c3eda1 into angular:master Mar 10, 2021
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extension Relates to an issue with the VS Code extension ivy Feature / enhancement / bug fix in Ivy perf Performance issue user XP Issue related to user experience view engine issues that affect View Engine language service only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When Ivy is enabled, TypeScript code is super slow
2 participants