-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
private async importDataFrameScripts(): Promise<void> { | ||
try { | ||
// Run our dataframe scripts only once per session because they're slow | ||
const key = this.debugService.activeDebugSession?.id; |
There was a problem hiding this comment.
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})`, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 Report
@@ 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
|
# 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): |
There was a problem hiding this comment.
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)
// 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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
cb437af
to
08251bc
Compare
Fixes #10516