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

API usage guidelines #22994

Closed
DonJayamanne opened this issue Feb 28, 2024 · 4 comments · Fixed by #23010
Closed

API usage guidelines #22994

DonJayamanne opened this issue Feb 28, 2024 · 4 comments · Fixed by #23010
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@DonJayamanne
Copy link

DonJayamanne commented Feb 28, 2024

It feels like accessing the known property can result in a lot of code getting executed, even if its just logging (i.e. 1,500 entries in a few seconds is a lot of logging).

Here #22993

Also looking at the code in Python extension

        get known(): Environment[] {
            sendApiTelemetry('known');
            return discoveryApi
                .getEnvs()
                .filter((e) => filterUsingVSCodeContext(e))
                .map((e) => convertEnvInfoAndGetReference(e));
        },

There's a lot going on here, hence it feels like I (as a a user of the above API) would need to be careful accessing this 100s of times.
As this could unnecessarily chew CPU,

Question

  • Should we (consumers of the API) cache the value of known
  • Is it possible for Python extnsion to instead cache the known value into a property, after all there are events for triggering the changes, hence that feels like its doable.

Anyways, asking this as I fear that changes in Jupyter to now access know everytime we need somethign is actually going to slow the extnsion host significantly as theres a lot going on here,
I.e. calling this 100s of times in a few ms could cause issues (after all this is what I was experiencing)

Note:

  • When I opened the Jpuyter kernel picker and attempted to select a Python environment, I did notice some sluggishness in the UI
  • Possible it was unrelated, but I thought of checking the logs and then saw the logging and then looked at the API implementation, hence this issue
@DonJayamanne DonJayamanne added the triage-needed Needs assignment to the proper sub-team label Feb 28, 2024
@DonJayamanne
Copy link
Author

I have found that accessing environment.known and getting the env details by searching this is very slow.
Basically Jupyter extension is almost 10 times slower in finding kernels now.
In stable version kernel picker is populated in 4 seconds.
In the latest versionn with the changes to query environments.known instead of using our own cached object, it now takes >30s

@karrtikr
Copy link

karrtikr commented Feb 29, 2024

Thanks for all the investigation.

environments.known is indeed misleading as a property in the external API type, when it really should probably be a function so it indicates that it is not as cheap. It currently:

  1. Figures out caller extension from stack in background
  2. Sends API usage telemetry
  3. Converts legacy environments types to external API types
  4. Filtering

Based on offline testing 1. and 3. are the main bottlenecks, which should be solved with #22998 and #20240 respectively for the long term. 3 requires a big change, so until we get to it, currently every call to environments.known still takes 1 ms, which can be significant if there are 10000 calls.

Regarding API guidelines,

Let me know if you have any questions.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Feb 29, 2024
@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Mar 1, 2024
karrtikr pushed a commit that referenced this issue Mar 1, 2024
Closes #22994 closes
#22993

Temporarily build our own known cache from which we return envs instead.
@DonJayamanne
Copy link
Author

I think we should reopen this
As the solution might now be different if changes are going to be made to python extension to improve the performance (remove previously mentioned bottle necks)

Else someone looking at this issue world try this solution which might now be right

@karrtikr
Copy link

karrtikr commented Mar 3, 2024

Please let me know once calling extension id PR is fixed and I can add the link to updated guidelines here, in case someone runs into the issue. Until then the guideline stated in the issue is true.

@github-actions github-actions bot added info-needed Issue requires more information from poster and removed info-needed Issue requires more information from poster labels Mar 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2024
wesm pushed a commit to posit-dev/positron that referenced this issue Apr 5, 2024
Closes microsoft/vscode-python#22994 closes
microsoft/vscode-python#22993

Temporarily build our own known cache from which we return envs instead.
wesm pushed a commit to posit-dev/positron that referenced this issue Apr 8, 2024
Closes microsoft/vscode-python#22994 closes
microsoft/vscode-python#22993

Temporarily build our own known cache from which we return envs instead.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants