Skip to content

Fix code lens perf for interactive window #11142

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

Merged
merged 12 commits into from
Apr 14, 2020
Merged

Conversation

rchiodo
Copy link

@rchiodo rchiodo commented Apr 13, 2020

For #10971

Fix the perf of code lens generation by changing how we do a bunch of things.

  1. Don't regen the code lens twice on every execute. Only necessary to do it once (when the cell is finished). Used to also do it when the hash was updated (during pre execute)
  2. Cache code lens ranges based on document version number. Not necessary to recompute if a file hasn't actually changed. Computing cell ranges is expensive as it does a regex on every line of the file.
  3. Cache code lens for the ranges based on the same version number. Not necessary to recreate unless the user changes the file or changes their settings.
  4. Cache the 'goto' code lens based on if a document has executed any code or not.

Also got rid of the cellhashlogger as it was unnecessary. The cellHashProvider is a notebook execution logger. It doesn't need the in between piece.

@@ -14,6 +14,7 @@ import {
TextEditorRevealType
} from 'vscode';

import { IDisposable } from 'monaco-editor';
Copy link
Author

Choose a reason for hiding this comment

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

IDisposable [](start = 9, length = 11)

Crap, Wrong one.

return Uri.parse(Identifiers.InteractiveWindowIdentity);
return {
resource: Uri.parse(Identifiers.InteractiveWindowIdentity),
type: 'interactive'
Copy link
Author

Choose a reason for hiding this comment

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

We need a type here so that the codeLensFactory can only initiailize it's hash provider when the notebook for the interactive window is created. It's a singleton so we don't want to reinit the hash provider on every notebook open.

@@ -101,6 +81,12 @@ export class CellHashProvider implements ICellHashProvider, IInteractiveWindowLi
.filter((e) => e.hashes.length > 0);
}

public restartedKernel() {

Choose a reason for hiding this comment

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

Suggested change
public restartedKernel() {
public onKernelRestarted() {

As we're reacting to an event that took place (i.e. this is meant to be an event handler), I think onKernelRestarted is better

Copy link
Author

Choose a reason for hiding this comment

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

Sure.


In reply to: 407773224 [](ancestors = 407773224)

@codecov-io
Copy link

codecov-io commented Apr 13, 2020

Codecov Report

Merging #11142 into master will decrease coverage by 61.47%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #11142       +/-   ##
===========================================
- Coverage   61.47%    0.00%   -61.48%     
===========================================
  Files         597       11      -586     
  Lines       32801       37    -32764     
  Branches     4640        4     -4636     
===========================================
- Hits        20163        0    -20163     
+ Misses      11622       37    -11585     
+ Partials     1016        0     -1016     
Impacted Files Coverage Δ
src/client/constants.ts 0.00% <0.00%> (-100.00%) ⬇️
src/client/debugger/constants.ts 0.00% <0.00%> (-100.00%) ⬇️
src/client/common/process/constants.ts 0.00% <0.00%> (-100.00%) ⬇️
src/client/common/platform/constants.ts 0.00% <0.00%> (-100.00%) ⬇️
src/client/interpreter/autoSelection/constants.ts 0.00% <0.00%> (-100.00%) ⬇️
src/client/interpreter/locators/services/conda.ts 0.00% <0.00%> (-100.00%) ⬇️
...t/datascience/jupyter/jupyterDataRateLimitError.ts 0.00% <0.00%> (-50.00%) ⬇️
src/client/datascience/commands/serverSelector.ts
...bugger/extension/adapter/outdatedDebuggerPrompt.ts
src/client/providers/objectDefinitionProvider.ts
... and 569 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56051b8...18f7582. Read the comment docs.

}
private onChangedSettings() {
// When config settings change, refresh our code lenses.
this.codeLensCache.clear();
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it's on any settings change.

Copy link
Member

Choose a reason for hiding this comment

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

I think there is that .affectConfiguration function we should be using here. Or else we are clearing these out too much.

Copy link
Author

Choose a reason for hiding this comment

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

No there isn't. Not on the config settings. That's on the workspaceConfiguration.

Copy link
Author

Choose a reason for hiding this comment

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

And the worst case is that the code lens are regenerated whenever you change your python settings. Meh.

Copy link
Author

Choose a reason for hiding this comment

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

You can see where the configSettings uses that 'affectsConfiguration' in the configSettings.ts file (line 571 or so). It will only fire an onDidChangeSettings when the python settings change.


In reply to: 407782405 [](ancestors = 407782405)

Copy link
Author

Choose a reason for hiding this comment

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

We should probably recompute the code lenses though. Otherwise the next execution will recompute them all.


In reply to: 407782955 [](ancestors = 407782955,407782405)

this.updateRequiredDisposable = this.codeLensFactory.updateRequired(this.onCodeLensFactoryUpdated.bind(this));

// Make sure to stop listening for changes when this document closes.
this.documentManager.onDidCloseTextDocument(this.onDocumentClosed.bind(this));
Copy link
Member

Choose a reason for hiding this comment

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

This is disposable.

Copy link
Author

Choose a reason for hiding this comment

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

Whoops, will fix.


In reply to: 407782600 [](ancestors = 407782600)

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rchiodo rchiodo merged commit eab579f into master Apr 14, 2020
@rchiodo rchiodo deleted the rchiodo/codelens_perf branch April 14, 2020 00:23
rchiodo added a commit that referenced this pull request Apr 14, 2020
* Eliminate first level of redundancy

* Working with a cache

* Add test to verify no more generating cell ranges

* Add news entry

* Clean up on closing

* Make sure close and reopen works

* Fix sonar errors

* Fix restart

* Fix wrong IDisposable type

* Rename restartedKernel to onKernelRestarted

* Recompute when changing settings

* Clear out document close event when document closes
rchiodo added a commit that referenced this pull request Apr 14, 2020
* Fix code lens perf for interactive window (#11142)

* Eliminate first level of redundancy

* Working with a cache

* Add test to verify no more generating cell ranges

* Add news entry

* Clean up on closing

* Make sure close and reopen works

* Fix sonar errors

* Fix restart

* Fix wrong IDisposable type

* Rename restartedKernel to onKernelRestarted

* Recompute when changing settings

* Clear out document close event when document closes

* Update changelog

* Fix build error from missing file
@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants