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

Refactor how variables and DF info is fetched #10557

Merged
merged 12 commits into from
Jun 28, 2022
Merged

Refactor how variables and DF info is fetched #10557

merged 12 commits into from
Jun 28, 2022

Conversation

DonJayamanne
Copy link
Contributor

Fixes #10516

@DonJayamanne DonJayamanne requested a review from a team as a code owner June 23, 2022 23:44
private async importDataFrameScripts(): Promise<void> {
try {
// Run our dataframe scripts only once per session because they're slow
const key = this.debugService.activeDebugSession?.id;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This same code was repeated in two places, now one place

const results = await this.evaluate(
`${GetVariableInfo.VariableInfoFunc}(${variable.name})`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem here is when debugging we have an await and its possible after we first import the scripts the stack frame has changed, hence the variables will be lost (not in scope).

This fixes that by ensureing that the function call always imports the necessary scripts (previously it was done seprately)

Copy link
Contributor

Choose a reason for hiding this comment

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

THe original code worked because of it loading a module but also had the added benefit of it not needing to be loaded more than once.

Could we change the new code to create a module to accomplish the same thing? So we don't have to load it more than once?

Copy link
Contributor

Choose a reason for hiding this comment

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

Meaning we wouldn't have to recreate the functions on every stack frame.

The side benefit is we would have less extra cruft in the debugger variable list too.

Copy link
Contributor Author

@DonJayamanne DonJayamanne Jun 24, 2022

Choose a reason for hiding this comment

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

I do'nt see any harm in re-creating (re-loading this everytime).
Also we cannot go with a module as that won't work in web/remote.

I'll update the code to delete the imported namespaces & the functions.

Baically change to as follows:

import xyz
def __vsc_getDataFrameInfo():
....

print(results)

delete xyz
del __vsc_getDataFrameInfo

This way we clean up all of the imports and also the function definitions we create.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see that as being an issue, its not a large chunk of code that could slow things down, only runs when the user has stopped at a stack frame & running that code is super fast

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could leave the module there. We did before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't need to reload on EVERY variable request

Agree, however running such code is very simple & fast.
Also not leaving the module as users have already complained about *.vscode variables, next they'll complain about the modules as well, hence figured its better to clean that up.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it depends upon how long this extra code takes to run. Could have up to 30 requests for this (assuming variable view was showing 30 variables at a time)

Do you have any idea how long it takes? 50ms each eval? 100ms?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could only load and delete it once per frame? Does python have destructors? (Was thinking of how to delete on scope leaving)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could have up to 30 requests for this (assuming variable view was showing 30 variables at a time)

Will check.
FYI - we only have this when debugging, e.g. in regular execution, we send everything as a single request.
Will look into the execution times now.

@codecov-commenter
Copy link

codecov-commenter commented Jun 24, 2022

Codecov Report

Merging #10557 (9d61910) into main (f548f40) will decrease coverage by 0%.
The diff coverage is 77%.

❗ Current head 9d61910 differs from pull request most recent head d573ac4. Consider uploading reports for the commit d573ac4 to get more accurate results

@@          Coverage Diff           @@
##            main   #10557   +/-   ##
======================================
- Coverage     71%      71%   -1%     
======================================
  Files        473      475    +2     
  Lines      28025    28050   +25     
  Branches    4698     4706    +8     
======================================
+ Hits       19968    19977    +9     
- Misses      6189     6191    +2     
- Partials    1868     1882   +14     
Impacted Files Coverage Δ
src/platform/common/scriptConstants.ts 100% <ø> (ø)
src/kernels/variables/pythonVariableRequester.ts 55% <61%> (-15%) ⬇️
src/kernels/variables/debuggerVariables.ts 68% <65%> (-2%) ⬇️
src/platform/common/variableScriptGenerator.ts 75% <75%> (ø)
src/platform/common/dataFrameScriptGenerator.ts 90% <90%> (ø)
src/platform/common/serviceRegistry.node.ts 100% <100%> (ø)
src/platform/common/types.ts 100% <100%> (ø)
src/kernels/kernelDependencyService.node.ts 81% <0%> (-5%) ⬇️
src/kernels/variables/kernelVariables.ts 56% <0%> (-2%) ⬇️
... and 8 more

@DonJayamanne DonJayamanne marked this pull request as draft June 24, 2022 00:24
@DonJayamanne DonJayamanne removed the request for review from a team June 24, 2022 00:24
# Query Jupyter server for the info about a dataframe
import json as _VSCODE_json
import builtins as _VSCODE_builtins
def _VSCODE_getVariable(what_to_get, *args):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rchiodo I've modified the code so that everything is under a function now, all we need to do is delete the imported modules & delete this function that we declare (when cleaning up).
If we were to import a module, we'd still need to delete the imported module,

Now we should not end up with tonnes of function definitinos as everything is local to this one function, hence no need to clean those individual functions (as its all local & goes out of scope)

@DonJayamanne DonJayamanne marked this pull request as ready for review June 24, 2022 01:33
// Sample output is `["test", "test2", "os", "sys"]`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const vars = ((outputs[0].data as any)['text/plain'] as string)
.trim()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new test to ensure we don't leave any messy variables behind

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed a bug to remove os & sys (stuff that we add when starting kernels & the like)

@DonJayamanne DonJayamanne force-pushed the issue10516 branch 2 times, most recently from cb437af to 08251bc Compare June 26, 2022 22:36
@DonJayamanne DonJayamanne merged commit 975fb96 into main Jun 28, 2022
@DonJayamanne DonJayamanne deleted the issue10516 branch June 28, 2022 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NameError: name '_VSCODE_getVariableInfo' is not defined
3 participants