microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 769 forks source link

Enabling sync server makes web version super slow #5381

Open rchiodo opened 7 months ago

rchiodo commented 7 months ago

It makes sense, but it's not really usable.

here's some timings for reading site-packages files:

[FG] parsing: file:///Testing_Pyright/.venv/lib/site-packages/_pytest/logging.py [fs read 0ms] (815ms)
[FG] binding: file:///Testing_Pyright/.venv/lib/site-packages/_pytest/logging.py (73ms)
[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/re.pyi [fs read 0ms] (282ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/re.pyi (46ms)
[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/enum.pyi [fs read 0ms] (226ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/enum.pyi (40ms)
[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/logging/__init__.pyi [fs read 0ms] (491ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/logging/__init__.pyi (93ms)
[FG] parsing: file:///Testing_Pyright/.venv/lib/site-packages/_pytest/monkeypatch.py [fs read 0ms] (343ms)
[FG] binding: file:///Testing_Pyright/.venv/lib/site-packages/_pytest/monkeypatch.py (32ms)
[FG] parsing: file:///Testing_Pyright/.venv/lib/site-packages/_pytest/recwarn.py [fs read 0ms] (201ms)
[FG] binding: file:///Testing_Pyright/.venv/lib/site-packages/_pytest/recwarn.py (24ms)
[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/warnings.pyi [fs read 0ms] (89ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/warnings.pyi (12ms)

The parse time is about 10x what we'd get locally.

There's something else that's weird, it seems we rebind/parse builtins over and over again:

[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 0ms] (1950ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/builtins.pyi (395ms)
[FG] binding: file:///Testing_Pyright/test_django.py_chained___skip__completion__.py (0ms)
[FG] parsing: file:///Testing_Pyright/test_django.py (39ms)
[FG] binding: file:///Testing_Pyright/test_django.py (9ms)
[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/bundled/stubs/django-stubs/db/models/base.pyi [fs read 0ms] (79ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/bundled/stubs/django-stubs/db/models/base.pyi (16ms)
[FG] parsing: file:///Testing_Pyright/.venv/lib/site-packages/django/db/models/base.py (59ms)
[FG] binding: file:///Testing_Pyright/.venv/lib/site-packages/django/db/models/base.py (3ms)
[FG] parsing: file:///Testing_Pyright/test_django.py_chained___skip__completion__.py (0ms)
[FG] parsing: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 0ms] (1909ms)
[FG] binding: https://ms-python.vscode-unpkg.net/ms-python/vscode-pylance/2023.12.104/extension/dist/typeshed-fallback/stdlib/builtins.pyi (373ms)
[FG] binding: file:///Testing_Pyright/test_django.py_chained___skip__completion__.py (0ms)

This is with no changes.

rchiodo commented 7 months ago

I think we may be using the remote file API for the dist.url as well. That would be part of the problem. We should be able to use the old way to read stuff from the dist folder.

rchiodo commented 6 months ago

Part of the problem here is the bundle is obfuscated. Splitting the bundle is harder than it was in AZNB because VS code rewrites the Worker object to not allow us to pass our own blob.url (where we rewrite the worker import scripts). They're passing their own blob url where they rewrite the importScripts here: https://github.com/microsoft/vscode/blob/1be73b4a517ad5c4b6361b1fdbeedb8fc6d0d3a1/src/vs/workbench/api/worker/extensionHostWorker.ts#L131

Might need to look into computing this at runtime (and overwrite what webpack does in its calls to importScripts). Hard part is getting the distUrl to the webpack script.

This might be a function of writing a placeholder for the worker that actually has its own calls to importScripts?

Something like:


self.onMessage((msg) => {
   // At this point here it should be able to rewrite importScripts because we're
   // already loaded in to the browser.
   importScripts('./browser.async.bundle.js');
});