Skip to content

TypeScript support in VSCode become unresponsive  #92583

Closed

Description

@ezarya

Issue Type: Bug

Nothing specific. Just working with TypeScript code and doing some refactoring. More ofter occurs when trying to rename symbol.

Processing arrows keep rolling forever:
Screenshot 2020-03-12 at 16 50 22

Extensions log

[2020-03-12 16:48:36.952] [exthost] [error] [vscode.typescript-language-features] provider FAILED
[2020-03-12 16:48:36.952] [exthost] [error] Error: busy
	at o._provideSemanticTokens (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features/dist/extension.js:1:180337)

VS Code version: Code 1.43.0 (78a4c91, 2020-03-09T19:34:44.548Z)
OS version: Darwin x64 18.7.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 x 2600)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 32.00GB (2.45GB free)
Process Argv
Screen Reader no
VM 0%
Extensions: none

Activity

  1. nathonius commented on Mar 13, 2020

    @nathonius

    I'm seeing similar behavior, though restarting the TS server seemed to fix it for me temporarily. Also seeing #92652 , and restarting the TS server fixed that for me as well. However, on restarting VS Code, the problem comes back. It's inconsistent though.

    Version: 1.44.0-insider (user setup)
    Commit: efd7548
    Date: 2020-03-13T06:05:25.782Z
    Electron: 7.1.11
    Chrome: 78.0.3904.130
    Node.js: 12.8.1
    V8: 7.8.279.23-electron.0
    OS: Windows_NT x64 10.0.18362

  2. mckn commented on Mar 16, 2020

    @mckn

    I'm seeing the same issue. But the following process spins up and takes more then 100% of the CPU.

    /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/zd/0zb6dxm95s7_d0_vwt2_bfch0000gn/T/vscode-typescript501/2c14536d71655c3c603f/tscancellation-53c31963055dafeda08a.tmp* --globalPlugins typescript-vscode-sh-plugin --pluginProbeLocations /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation

    Version: 1.43.0
    Commit: 78a4c91
    Date: 2020-03-09T19:34:44.548Z
    Electron: 7.1.11
    Chrome: 78.0.3904.130
    Node.js: 12.8.1
    V8: 7.8.279.23-electron.0
    OS: Darwin x64 19.3.0

  3. nathonius commented on Mar 16, 2020

    @nathonius

    I'm no longer seeing this behavior. Not sure if something was fixed in newer insiders releases or if it was just something temporal.

  4. midnight-dev commented on Mar 17, 2020

    @midnight-dev

    I can confirm this behavior while working on mostly JavaScript. At first I thought it was my poorly scoped monolithic JS file, (and I've been slowly losing my mind since Google and GitHub seemed to be unaware of such an issue a week ago).

    Brief spec:

    VSCode 1.43 (stable) with TS 3.8.3 (stock), on Windows 10 x64 | 4c/8t Intel CPU, 32GiB RAM

    VSCode linting / IntelliSense for JavaScript breaks seemingly for every new token or expression typed until the TS language server recovers from a seizure. Simply undoing or redoing a few times will litter the extension host output with this while TS/JS server tries to unbork itself.

    Extension host terminal output:

    [2020-03-17 10:11:59.613] [exthost] [error] [vscode.typescript-language-features] provider FAILED
    [2020-03-17 10:11:59.613] [exthost] [error] Error: busy
    	at o._provideSemanticTokens (c:\Program Files\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:180337)
    [2020-03-17 10:12:00.142] [exthost] [error] [vscode.typescript-language-features] provider FAILED
    [2020-03-17 10:12:00.142] [exthost] [error] Error: busy
    	at o._provideSemanticTokens (c:\Program Files\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:180337)
    [2020-03-17 10:12:00.729] [exthost] [error] [vscode.typescript-language-features] provider FAILED
    [2020-03-17 10:12:00.730] [exthost] [error] Error: busy
    	at o._provideSemanticTokens (c:\Program Files\Microsoft VS Code\resources\app\extensions\typescript-language-features\dist\extension.js:1:180337)
    

    Typing out the following in any JavaScript file (on the latest stable version of VSCode) would result in 3 or 4 reinitializations for the language server:

    if (existingVariable === existingArray[0]) {
        console.log(`${existingArray} already contains ${existingVariable}`);
    }

    Enabling logging or tracing doesn't point to an obvious suspect, though I don't have much experience reading those. No relevant results come up when searching through for the obvious "error", "fail", and "busy" keywords. I couldn't find "_provideSemanticTokens" either regardless of the level of verbosity. I'd include some samples, however, most of the code I'm working with is sensitive.

    Version: 1.43.0 (system setup)
    Commit: 78a4c91
    Date: 2020-03-09T19:47:57.235Z
    Electron: 7.1.11
    Chrome: 78.0.3904.130
    Node.js: 12.8.1
    V8: 7.8.279.23-electron.0
    OS: Windows_NT x64 10.0.18363

    I'm not running with major changes. Using TypeScript 3.8.3 that VSCode comes with. Although I only see 40-60% CPU utilization for several seconds, this is making it a pain to get things done. Depending on the size of the JavaScript file open, IntelliSense seems to take longer to show up and syntax highlighting sometimes decides it should re-render. Anything except reading or scrolling through JavaScript now thrashes my CPU cores. Increasing the memory allowance to the TS server from the default of 3072 MiB to 4096 MiB did not help, and I couldn't find any settings relating to time thresholds.

    Disabling all extensions (except built-ins) does not change this behavior. The size of the file doesn't seem to matter. Manually restarting the TS server does not actually help in my case. All it seems to do is quiet down the UI notification that the server features are rebooting. The laggy UX / linting / IntelliSense symptoms are still present and the ext host logs still come up with busy / fail errors.

    Apologies for creating a wall of text, but I'm hoping this will help someone quickly submit a fix. Here is where the ext host error points to (formatted for readability).

    class o {
        constructor(e) {
            this.client = e
        }
    
        getLegend() {
            return new r.SemanticTokensLegend(u, l)
        }
    
        async provideDocumentSemanticTokens(e, t) {
            const n = this.client.toOpenedFilePath(e);
    
            return n ? this._provideSemanticTokens(e, {
                file: n, 
                start: 0, 
                length: e.getText().length
            }, t) : null
        }
    
        async provideDocumentRangeSemanticTokens(e, t, n) {
            const r = this.client.toOpenedFilePath(e);
    
            if (!r)
                return null;
    
            const i = e.offsetAt(t.start), 
                  s = e.offsetAt(t.end) - i;
    
            return this._provideSemanticTokens(e, { 
                file: r, 
                start: i, 
                length: s 
            }, n)
        }
    
        async _provideSemanticTokens(e, t, n) {
            if (!this.client.toOpenedFilePath(e))
                return null;
    
            const i = e.version, 
                  s = await this.client.execute("encodedSemanticClassifications-full", t, n);
    
    
            if ("response" !== s.type || !s.body) return null;
    
            if (i !== e.version) throw new Error("busy");
    
            const o = s.body.spans, 
                  u = new r.SemanticTokensBuilder;
    
            let l = 0;
    
            for (; l < o.length;) {
                const t = o[l++], 
                      n = o[l++], 
                      r = o[l++];
    
                let i = 0, s = a(r);
    
                if (void 0 !== s) i = c(r);
                else if (void 0 === (s = h[r]))
                    continue;
    
                const p = e.positionAt(t), 
                      d = e.positionAt(t + n);
    
                for (let t = p.line; t <= d.line; t++) {
                    const n = t === p.line ? p.character : 0, 
                          r = t === d.line ? d.character : e.lineAt(t).text.length;
    
                    u.push(t, n, r - n, s, i)
                }
            }
    
            return new r.SemanticTokens(u.build())
        }
    }

    Even when still minified, the column 180337 isn't too useful, as it points to somewhere in the middle of new r.SemanticTokensBuilder but since the only error is "busy," I'd say it's probably trying to point at this, which does raise an eyebrow:

            if (!this.client.toOpenedFilePath(e))
                return null;
    
            const i = e.version, 
                  s = await this.client.execute("encodedSemanticClassifications-full", t, n);
    
    
            if ("response" !== s.type || !s.body) return null;
    
            if (i !== e.version) throw new Error("busy");

    If e is passed in and never mutated, and i is set to e.version and then later checked for that exact match, how can it not be equal to it? Since this check exists, I guess it has something to do with state and is expected behavior here. Hope this helps. If it's already fixed in Insiders, I'd greatly appreciate a hotfix for those of us still on stable.

    Edit: Fixed typo

  5. midnight-dev commented on Mar 21, 2020

    @midnight-dev

    Update:

    Upon installing version 1.43.1, I still noticed a TypeScript failure/busy error when typing or modifying tokens. I disabled semantic highlighting globally, and the failures stopped. The insane amount of CPU thrashing also stopped.

    This seems like a useful feature to have, but it's broken due to a busy timeout when some conditions are met. For people working on powerful workstations, they may not even notice it if the TypeScript language server reboots fast enough. With my settings and my JavaScript projects, it makes developing too difficult. The language features shouldn't crash every 4 seconds anyway. If anyone knows of a setting that might resolve the busy issues with semantic highlighting, please point me in the right direction.

  6. mckn commented on Mar 23, 2020

    @mckn

    Ben Arnett (@midnight-dev) will give that a try, thanks! Will get back here with a report.

  7. aeschli commented on Mar 26, 2020

    @aeschli
    Contributor

    I don't see any crashes, but I can confirm that while typing are a lot of semantic token requests fired and most of them discarded ('busy') for medium and large files.
    I can imagine that adds considerable load on the TS language server and explain what Ben Arnett (@midnight-dev) is seeing.

    Alexandru Dima (@alexdima), Can we throttle the requests until typing has ended?
    Also, the error message printed to the ext host log is misleading

    [2020-03-26 21:57:24.627] [exthost] [error] [vscode.typescript-language-features] provider FAILED
    [2020-03-26 21:57:24.627] [exthost] [error] Error: busy
    	at DocumentSemanticTokensProvider._provideSemanticTokens (/home/martin/workspaces/vscode/extensions/typescript-language-features/out/features/semanticTokens.js:68:19)
    
  8. midnight-dev commented on Mar 26, 2020

    @midnight-dev

    Alexandru Dima (@alexdima), Can we throttle the requests until typing has ended?

    I'd like to second that request. Also, does the semantic tokens provider scan through the entire document every time it updates the semantic tokens? If so, it would greatly improve performance if it only parsed the line(s) with an active cursor.

  9. 6 remaining items

  10. aeschli commented on Mar 29, 2020

    @aeschli
    Contributor

    What's special here is that editor doesn't throttle, always sends right after a change, but never sends more than one request. It waits for the last request to return until it fires the next.

    Knowing that, he provider takes a chance, ask the LS right away. If it turns out to be the only change, the result can be given back to the editor without any delay. If at the time of the response we see that the document has changed, we wait until the activity has stopped before telling the server that we failed.
    The server will then make a request right away.

    At least that's the idea, I hope I haven't overlooked anything. I also normally do it the other way around.

  11. alexdima commented on Mar 29, 2020

    @alexdima
    Member

    Initially, the semantic tokens request would be created 500ms after typing stopped. But in #86165 the complaint is that strategy makes semantic tokens update very slowly, making semantic tokens appear laggy.

    So with the changes for #86165, the request is created 300ms after the first typing, then the request is waited for, and then a new request is made if typing occurred again in the meantime, thus the rate is at most 1 every 300ms. I believe this is a sensible upper bound.

    The error is logged from here, that generic piece of code does not know about the special semantic of busy errors. Rather than teaching that piece of code about busy errors, I have created #93686 to track that we introduce a special error type in vscode.d.ts and that can be instance checked and ignored for logging.

  12. aeschli commented on Mar 29, 2020

    @aeschli
    Contributor

    Marking as fixed.
    Ben Arnett (@midnight-dev) Please give it a try.

  13. midnight-dev commented on Mar 29, 2020

    @midnight-dev

    Martin Aeschlimann (@aeschli) Is there a relatively painless way to get VSCode to use this new commit since it's ultimately just a piece of the TS language server? If not, I may have to wait for Insiders to catch up. It's currently on commit 6cf3dd9 from earlier in the week.

    I'm still a bit worried that there will be CPU spikes during normal, even casual development, albeit they shouldn't be as frequent. How much of the document is analyzed with every request? If there's an abnormally slow typist, they could see the same amount of CPU load as I'm currently seeing in Insiders. While the following isn't as bad as I've seen, just jotting down a few lines in small bursts normally wouldn't put a blip on resource monitors (even while the syntax highlighting updates as fast as possible).

    image

    image

    I'll be glad to try out the same exercise when I can get the language features to use your commit. 👍

  14. added
    bug
    on Mar 30, 2020
  15. connor4312 commented on Apr 3, 2020

    @connor4312
    Member

    Martin Aeschlimann (@aeschli) are there verification steps for this?

  16. added
    verification-steps-needed
    on Apr 3, 2020
  17. aeschli commented on Apr 3, 2020

    @aeschli
    Contributor

    To verify

  18. removed
    verification-steps-needed
    on Apr 3, 2020
  19. midnight-dev commented on Apr 8, 2020

    @midnight-dev

    Martin Aeschlimann (@aeschli) Unfortunately, I'm still seeing a lot of busy throws. It's definitely better than it was, but I'm finding myself trying to race the 300ms to prevent CPU spikes. Every missed keystroke or pause to let variable/function suggestions populate results in my laptop quickly becomes a toaster. I know this is in part the nature of various features like IntelliSense and the like, but I could have sworn developing on VSCode from a few months ago did not burn through as many CPU cycles.

    A couple things come to mind. Would it be simple to make the delay configurable, with 300ms being the default? And does the semantic tokens provider scan through the entire document during every request (or response)? Or is it only the current line(s) with an active cursor? The performance could be very different if it only tests the current lines for semantic differences.

  20. aeschli commented on Apr 9, 2020

    @aeschli
    Contributor

    Ben Arnett (@midnight-dev) Yes, currently the whole document is looked at. The next step is to switch to range based semantic highlighting. We'll try that first before making the delay configurable.

  21. locked and limited conversation to collaborators on May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugsemantic-tokenstypescriptverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions