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

Finding type info for functions can cause huge delays in displaying inline documentation if type hints aren't given #1895

Closed
MaddyGuthridge opened this issue Oct 1, 2021 · 4 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@MaddyGuthridge
Copy link

Environment data

  • Language Server version: v2021.9.4
  • OS and version: Windows 10 21H1
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.10 (WSL Ubuntu)

Expected behaviour

While type info is loaded for a function, inline documentation (docstrings) are displayed without the type annotations. If/when type info is determined, the hint is updated to include the information.

Actual behaviour

If type info isn't provided for a function, all inline documentation can take minutes to load as PyLance tries to determine return types for the function.

Logs

User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonJediLSP'
User belongs to experiment group 'pythonDiscoveryModuleWithoutWatcher'
User belongs to experiment group 'pythonTensorboardExperiment'
User belongs to experiment group 'PythonPyTorchProfiler'
User belongs to experiment group 'pythonDeprecatePythonPath'
User belongs to experiment group 'pythonSortEnvs'
User belongs to experiment group 'pythonRunFailedTestsButtonDisplayed'
User belongs to experiment group 'pythonRefreshTestsButtonDisplayed'
User belongs to experiment group 'pythonRememberDebugConfig'
Python interpreter path: ./.venv/bin/python
Starting Pylance language server.
Error 2021-10-01 16:29:28: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://wsl+ubuntu/home/migue/.config/Code/User/settings.json' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu/home/migue/.config/Code/User/settings.json')
	at _handleError (/home/migue/.vscode-server/bin/7f6ab5485bbc008386c4386d08766667e155244e/out/vs/server/remoteExtensionHostProcess.js:94:160087)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)
	at async y.readText (/home/migue/.vscode-server/extensions/ms-python.python-2021.9.1246542782/out/client/extension.js:9:314351)
	at async p.doesFileNeedToBeFixed (/home/migue/.vscode-server/extensions/ms-python.python-2021.9.1246542782/out/client/extension.js:59:823969)
	at async /home/migue/.vscode-server/extensions/ms-python.python-2021.9.1246542782/out/client/extension.js:59:823096
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (/home/migue/.vscode-server/extensions/ms-python.python-2021.9.1246542782/out/client/extension.js:59:823042)
	at async p.updateTestSettings (/home/migue/.vscode-server/extensions/ms-python.python-2021.9.1246542782/out/client/extension.js:59:822669)] {
  code: 'FileNotFound'
}
> conda --version

Code Snippet / Additional information

Steps to reproduce:

  1. Install SymPy (a complex mathematical toolkit that doesn't currently have type annotations
  2. In a new file, import sympy, and make a call to the function sympy.solve()
  3. Mouse over the function. Observe that loading the documentation for the function takes minutes, as PyLance parses nearly the entirety of SymPy's codebase to try to find the return types.

It seems that I'm not the first to notice this issue: #946

I hope this performance issue can be fixed soon!

@github-actions github-actions bot added the triage label Oct 1, 2021
@jakebailey
Copy link
Member

I would normally close this as a dupe of #946, but you're suggesting the concrete change of only showing the type information once it's available, and to show things like docstrings if we have them faster.

The general problem is that there's no way to do this in VS Code or the LSP; it asks for a hover, then waits for the full result, and then that's it. Pylance will cache the info so it's fast the next time, but otherwise, there's no way to update it once we send it back. We could send a limited response and then have a more complete one later, but it would only appear if you exit the hover and come back again.

sympy is a really complicated library, so it tends to be slow the first time you interact with it; stubs help.

@MaddyGuthridge
Copy link
Author

I'd say that although it'd be possible to get stubs for libraries, it'd effectively be a game of cat and mouse trying to find or create stubs for any library that happens to have the same issue. I know that I've had issues for some of my own personal projects where certain situations have caused similar lag, so it's not like this issue is isolated to SymPy (even if in my case it was due to bad design :P ).

I think a good compromise is to set a time-out (eg 1 second) for the types to load and then just return the information without type hints if it isn't loaded at that point, and then update it on later occasions if necessary, although it could be an idea to actually add the ability to update the hints after they've displayed in VS Code.

@jakebailey
Copy link
Member

I've checked and Eric's change for #1890 also significantly improves sympy performance. In this case, typing sympy.solve froze for minutes (as you noted), but after, it's practically instant, at the cost of an imperfect return type.

I'm going to mark this one as fixed, but going further to improve the type will definitely take a stub or upstream to annotate their code.

@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Oct 4, 2021
@github-actions github-actions bot removed the triage label Oct 4, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.10.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2021100-6-october-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

2 participants