Closed Kallamez closed 3 years ago
Thanks for the bug report. I'm seeing what appears to very slow analysis or perhaps an infinite loop. I'll investigate further to determine the root cause.
Further testing: I added the ssss
variable and left it undefined just to see what happened. This is the new log:
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:1 [found 121 items] (364ms)
[BG(1)] checking: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (1456ms)
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (1730ms)
Background analysis message: getSemanticTokens full
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:3 ...
[FG] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (22ms)
[FG] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:3 [found 3 items] (33ms)
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:4 ...
[FG] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (12ms)
[FG] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (4ms)
[FG] completion at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py:380:4 [found 1 items] (20ms)
[FG] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (15ms)
[FG] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (12ms)
[BG(1)] getSemanticTokens full at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)] parsing: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\types.pyi [fs read 1ms] (14ms)
[BG(1)] binding: c:\Users\Tosh0kan\.vscode\extensions\ms-python.vscode-pylance-2021.8.1\dist\typeshed-fallback\stdlib\types.pyi (15ms)
[BG(1)] getSemanticTokens full at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (261822ms)
[Info - 3:33:29 PM] [BG(1)] Long operation: getSemanticTokens full at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (261822ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:0 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (4ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: analyze
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:2 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (7ms)
[BG(1)] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (10ms)
[BG(1)] getSemanticTokens range 314:0 - 380:2 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (17ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:3 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] getSemanticTokens range 314:0 - 380:3 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (12ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:4 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (8ms)
[BG(1)] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] getSemanticTokens range 314:0 - 380:4 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (15ms)
Background analysis message: setFileOpened
Background analysis message: markFilesDirty
Background analysis message: getSemanticTokens range
[BG(1)] getSemanticTokens range 314:0 - 380:5 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)] parsing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] binding: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (6ms)
[BG(1)] getSemanticTokens range 314:0 - 380:5 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (236949ms)
[Info - 3:37:26 PM] [BG(1)] Long operation: getSemanticTokens range 314:0 - 380:5 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (236949ms)
Background analysis message: analyze
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py ...
[BG(1)] checking: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (142ms)
[BG(1)] analyzing: h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (142ms)
Background analysis message: getSemanticTokens delta
[BG(1)] getSemanticTokens delta previousResultId:1629224947469 at h:\01 Libraries\Documents\Tosh0kan Studios\Coding\GURPS Space\new Planet Generator.py (181ms)
Background analysis message: resumeAnalysis
Apparently, it's taking around 4 minutes for it to process my file.
Yes, I'm seeing analysis times of about 3 minutes.
The challenge is that this is a single, very complex block of code with multiple nested loops and conditional checks. It also has 71 local variables, none of which have type annotations, so types need to be inferred for all of them based on assigned values. When you place the entire block in a while loop, many of these variables' types depend on each other, so they all need to be solved and re-solved until all of the types converge. The analysis time grows exponentially under these circumstances.
I'll investigate whether there are mitigations we can add to the type analysis engine, but there will be limits to what we can do here.
You can work around the issue by factoring your code into proper subroutines. This will have the side benefit of making the code easier to understand and maintain as well.
I see. Yeah, apologies for the messy code. I'm really new to python (just two weeks), so I'll follow your advice and see how that fares. Thank you for the advice. 🙇♂️
I've found some optimizations that allow the type analyzer to avoid a bunch of costly work when analyzing complex nested code flow graphs like the one in this sample. This reduces the analysis time from 178s to under 1s on my machine. This optimization will be in the next release.
Amazing! Great work!
This issue has been fixed in version 2021.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202190-1-september-2021
Environment data
Expected behaviour
A green underline appearing underneath an undefined variable or a red underline appearing underneath incomplete expression, regardless of it being on the file itself, or any other script open in VSCode.
Actual behaviour
Both kinds of highlights completely stop working in the entire software. Any files already opened with such highlights retain them, even if the bad parts are corrected or removed, and any new errors won't be detected. I have to close the offending script, then restart VSCode for it to come back, but if I reopen the problematic script, it happens again.
Logs
Log of the Python Language Server. First opened VSCode, then opened the problematic script
Code Snippet / Additional information
GIF of the highlight working fine on the script when it doesn't have the while loop: https://i.imgur.com/WMxcXp5.gif
GIF of the highlight not working at all the same script when the while loop is present: https://i.imgur.com/IpGbLoT.gif