microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.67k stars 771 forks source link

Docs should include guidance on using Pylance on low power devices #5881

Open debonte opened 1 month ago

debonte commented 1 month ago

From Marketplace review:

Simon Howroyd 7 hours ago Works fine on desktop but in a dev container, particularly on lower power embedded ARM32 devices it has to be disabled. Main issue is if you save a file it seems to take a chunk of memory and cpu to "analyze files," if that has not completed and you save another file it takes another chunk of resources. Do that 3 or 4 times within a couple of minutes and it will crash my ARM32 application processor. Some guidance in the docs on how to use pylance on lower power devices would be very helpful.

howroyd commented 1 month ago

Thanks. If you need more details then please let me know

rchiodo commented 1 month ago

Can you include a log as described here?

https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue

My suspicion is that we're running out of memory. There are some things we outline here that you can do to alleviate that problem:

https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#exclude-unneeded-py-files-from-analysis

heejaechang commented 1 month ago

another data that could be helpful is providing this info (https://github.com/microsoft/pylance-release/wiki/Collecting-data-for-an-investigation.#collecting-cpuprofiles)

basically do

  1. start profiling
  2. save the file (assuming that is the repro step as described in the issue)
  3. stop profiling

and provide the profile data to us.

howroyd commented 1 month ago

I suspect out of memory too, the device only has 1GB RAM of which the container only really gets about 400-500MB. For reference this is running on a Dual ARM Cortex-A9 MPCore (600MHz).

I shall attempt some profiling but will need to ensure no sensitive info is in the logs, so please bear with me. It might also be tricky to get a representative profile of the full issue since that would cause a full crash. Will do my best!

heejaechang commented 1 month ago

@luabud we might want to add low resource mode where we turn off most of features except only core ones.

basically, only enables these features and turn off everything else.

  1. completion
  2. hover
  3. signature help
  4. go to definition/declartion/typedeclaration
  5. document symbol
  6. auto indentation
  7. format on type
  8. selection range
  9. folding range
  10. syntax errors
  11. open files only

turn off

  1. find all references
  2. highlight references
  3. pytest completion/hover/go to/...
  4. workspace symbols
  5. semantic errors
  6. semantic coloring
  7. inlay hints
  8. code actions
  9. indexing
  10. rename
  11. no worker threads
  12. no workspace diagnostics
  13. and anything expensive.

basically, we provide only cheap features that help typing but nothing else. it will be a little bit better than plain text.

heejaechang commented 4 days ago
         // No user files
        "python.analysis.exclude": ["**"],

        // Expensvie to turn on
        "python.analysis.indexing": false,
        "python.analysis.fixAll": [],
        "python.analysis.diagnosticMode": "openFilesOnly",
        "python.analysis.enablePytestSupport": false,
        "python.analysis.inlayHints.callArgumentNames": "off",
        "python.analysis.inlayHints.functionReturnTypes": false,
        "python.analysis.inlayHints.pytestParameters": false,
        "python.analysis.inlayHints.variableTypes": false,
        "python.analysis.supportRestructuredText": false,
        "python.analysis.typeCheckingMode": "off",
        "python.analysis.useLibraryCodeForTypes": false,

        // vscode settings that affect pylance feature but
        // expensive to turn on
        "editor.semanticHighlighting.enabled": false,
        "editor.occurrencesHighlight": "off",

        // okay to turn on if they want to
        "python.analysis.completeFunctionParens": false,
        "python.analysis.autoFormatStrings": false,
        "python.analysis.autoImportCompletions": false,
        "python.analysis.gotoDefinitionInStringLiteral": false,

here are settings user would want to make pylance behave like lightweight mode with existing pylance bits.

with this settings, editor related features such as completion, hover, signature help, syntax highlighting, go to definition and etc will continue to work but any advanced feature such as workspace symbol search, pytest hover/completion, inlay hint, auto imports, rename, semantic coloring and etc won't work.

Users can enable specific settings to activate features they want, however, because many features share the same underlying engines, enabling one feature might result in resource consumption similar to that of enabling multiple features.