vscode-clang icon indicating copy to clipboard operation
vscode-clang copied to clipboard

Heavy CPU usage when typing fast!!!

Open astinaam opened this issue 6 years ago • 12 comments

I am using Arch Linux. vscode Version 1.23.1 Commit d0182c3417d225529c6d5ad24b7572815d0de9ac Date 2018-05-10T16:04:33.747Z Shell 1.7.12 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64 I have an 8GB Ram and 1.7GHZ processor. When i type fast, my CPU become almost 100%. And when a folder with lot of files opened in the editor, then when i type fast the system freezes and i can't type anymore.

But with this extension disabled, everything seems to be working well.

astinaam avatar May 26 '18 00:05 astinaam

Am facing the same issue here on both VSCode version 1.25.0 (insiders) and 1.24.0 (stable). Arch Linux, 6GB RAM, x64 architecture and 2.6GHz processor.

kunparekh18 avatar Jun 21 '18 02:06 kunparekh18

Same issue here, I have noticed that this extension spams clang processes like crazy... up to moment when VS Code freezes.

XobSod avatar Jul 17 '18 13:07 XobSod

Same issue, the extension seems to spawn a lot of clang processes that eat all the CPU VsCode 1.25.1 Ubuntu 16.04, x64, 8GB RAM, Xeon 12 cores, 3.20GHz

Arpafaucon avatar Jul 18 '18 01:07 Arpafaucon

I'm having the same issue, if I even type 2 letters the CPU goes to 90% let alone trying to type more faster, vscode spawns way too many clang process VSCode 1.25.1 Linux Mint 18.09, 8GB RAM, Intel Core i5-3210M, 3.1GHz

rem1niscence avatar Jul 29 '18 02:07 rem1niscence

Solution: set: "clang.executable": "",

zhaoyewei avatar Aug 10 '18 11:08 zhaoyewei

i found another solution: disable clang dynamnoic.

zhaoyewei avatar Aug 14 '18 07:08 zhaoyewei

I'm using another solution:

while true
    pkill clang
end

recolic avatar Sep 09 '18 11:09 recolic

@mitaki28 Please fix this when you have time. This problem makes the extension unusable. Thanks.

tete1030 avatar Sep 10 '18 04:09 tete1030

Same issue here. I can only use the extension if one the options clang.completion.enabled or clang.diagnostic.enabled are false. Generally it is diagnostic that is the issue.

Platform: VS Code 1.28.0-Insider Arch LInux 4.14.9-arch1-1-ARCH, 8gb RAM, x64, Intel i5-6600K 3.40GHz

ashellwig avatar Sep 25 '18 03:09 ashellwig

In case anyone is still waiting for a solution here, I, being a js newbie, propose a monkey patch :smiley: In src/diagnostic.ts (~/.vscode/extensions/mitaki28.vscode-clang-*/out/src/diagnostic.ts), look for this function

export function registerDiagnosticProvider(selector: vscode.DocumentSelector, provider: DiagnosticProvider, name: string): vscode.Disposable {
    let collection: vscode.DiagnosticCollection = vscode.languages.createDiagnosticCollection(name);
    let cancellers = new Map<string, vscode.CancellationTokenSource>();
    let subsctiptions: vscode.Disposable[] = [];
    vscode.workspace.onDidChangeTextDocument((change) => {
        if (!vscode.languages.match(selector, change.document)) return;
        const uri = change.document.uri;
        const uriStr = uri.toString();
        if (cancellers.has(uriStr)) {
            cancellers.get(uriStr).dispose();
        }
        cancellers.set(uriStr, new vscode.CancellationTokenSource);
        delay(cancellers.get(uriStr).token).then(() => {
            cancellers.get(uriStr).dispose();
            cancellers.set(uriStr, new vscode.CancellationTokenSource);
            return provider.provideDiagnostic(change.document, cancellers.get(uriStr).token);
        }).then((diagnostics) => {
            cancellers.get(uriStr).dispose();
            cancellers.delete(uriStr);
            collection.set(uri, diagnostics);
        }, (_) => { /* do nothing */ });
    }, null, subsctiptions);
    return {
        dispose() {
            collection.dispose();
            for (let canceller of Array.from(cancellers.values())) {
                canceller.dispose();
            }
            vscode.Disposable.from(...subsctiptions).dispose();
        }
    };
}

, find the first occurrence of

        if (cancellers.has(uriStr)) {
            cancellers.get(uriStr).dispose();
        }

and change it into

        if (cancellers.has(uriStr)) {
            cancellers.get(uriStr).cancel();
            cancellers.get(uriStr).dispose();
        }

Depending on which version the vscode extension repo adopts, line number may vary; however as for now this patch works for me, namely, pressing one key on a .c file will not fork-bomb my computer with clang and clang-6.0 any more.

ThinerDAS avatar Oct 13 '18 08:10 ThinerDAS

@ThinerDAS Oh, that's right.

Now I have fixed this problem and published it.

Thank you.

mitaki28 avatar Oct 13 '18 16:10 mitaki28

@ThinerDAS Oh, that's right.

Now I have fixed this problem and published it.

Thank you.

It seems still not solved yet. version 0.2.3 has the same issue on my computer. Lot's of clang.exe fail to terminate themselves and eat up all my cpu time. This happens even if I type very slow, i.e., type a letter then wait 10 seconds then delete it, a clang.exe remains, eating up 40% of my cpu.

zjuwyz avatar Jul 06 '19 02:07 zjuwyz