Skip to content

API usage guidelines #22994

Closed
Closed

Description

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

Activity

  1. DonJayamanne commented on Feb 28, 2024

    @DonJayamanne
    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

  2. karrtikr commented on Feb 29, 2024

    @karrtikr

    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.

  3. DonJayamanne commented on Mar 2, 2024

    @DonJayamanne
    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

  4. karrtikr commented on Mar 3, 2024

    @karrtikr

    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.

  5. added
    info-neededIssue requires more information from poster
    and removed
    info-neededIssue requires more information from poster
    on Mar 3, 2024
  6. locked as resolved and limited conversation to collaborators on Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

triage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions