Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Nimsuggest uses 100% CPU usage with Nim 2.2.0

Open xTrayambak opened this issue 1 year ago • 7 comments

Description

Related issues:

Ever since NixOS's package cache started compiling nimlsp (and by extension, nimsuggest) against Nim 2.2.0, I've been noticing abnormally high CPU usage coming from nimsuggest, which often requires me to kill the language server (nimlsp) and restart it.

For now, we're circumventing this by forcing nimlsp to compile against Nim 2.0, but this is more of a bandaid fix than anything (we needed to fix this regression before the NixOS 24.11 merge window closed).

Please let me know if you need to know any other information. I'm using NixOS Unstable (24.11 Vicuna) on an AMD CPU, if that matters.

Nim Version

Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

active boot switches: -d:release

Current Output

No response

Expected Output

No response

Known Workarounds

Compiling nimlsp (and by extension, nimsuggest) against Nim 2.0

Additional Information

No response

xTrayambak avatar Nov 07 '24 05:11 xTrayambak

Does this happen on any specific code? Or on the development branch?

metagn avatar Nov 07 '24 19:11 metagn

It occurs in Nim 2.2.0, I haven't tried a development version to see if that works properly. It generally occurs when I open a moderately big file (~700-900 LoC) with various small functions.

xTrayambak avatar Nov 08 '24 11:11 xTrayambak

Some specific code where this happens would be appreciated, otherwise we can only guess what the issue is. A project is fine too but a minimal example would make it much easier to figure out the problem.

Also, does the same issue happen with nimlangserver?

metagn avatar Nov 10 '24 11:11 metagn

I'm seeing this too after updating to nim 2.2.0. nimlsp will peg to 100% and I have to kill it. nimlangserver fares better, but it will still frequently spike to 100% and stay there for 5 to 10 seconds. This is with neovim 0.10.2, if that matters.

I don't have a minimal repro yet but I'll try to get something together.

michaelnew avatar Nov 18 '24 20:11 michaelnew

I'm using Neovim too, if that matters. I'll link this file as it used to trigger this the most for me. It's around 900-ish lines long and uses templates, if that matters.

xTrayambak avatar Nov 19 '24 02:11 xTrayambak

It's very broken for me as well. My framework is fairly complex with lots of generics, concepts, macros, and templates. I can't share any of it right now, but I'll try to get a more minimal repro case. I'm working in Cursor IDE with the nim-lang extension. It keeps spawning more and more nimsuggest.exe instances, each competing for 100%. If I had to guess, it looks like what's happening on a high level is this:

  1. Nimsuggest is caught in an infinite loop
  2. Instance times out after 120 seconds, but is not terminated
  3. A new set of instances is spawned (i'm currently limiting my Max nimsuggest Processes to 4

Killing nimlangserver only seems to kill the most recently spawned instances that have not yet timed out. The other instances keep running at 100%.

Image

gmpreussner avatar Apr 27 '25 00:04 gmpreussner

Downloaded zed, installed the nim extension, then nimble install langserver. Restarted zed which had two tabs open to these files:

https://github.com/elcritch/figuro/blob/f1780ea39e6a4bf705dea7df4dc4281024947ff3/src/figuro/renderer/opengl.nim https://github.com/elcritch/figuro/blob/bee30c5e75c5232634144c9dcb843a4493fe2a73/src/figuro/runtime/runtimeNative.nim

runtimeNative.nim was the active tab.

Nim 2.2.4 - Linux / xubuntu

derek-v-s avatar May 03 '25 21:05 derek-v-s

If you are using vs code, search "nim suggest" in settings, set "max nimsuggest processes" to 1, set "nimsuggest idle timeout" to 20000. It will be much better.

zhmt avatar Jun 27 '25 10:06 zhmt

I will soon deprecate 2.0 nim in nixpkgs I will be updating to 2.2.6, if this isn't fixed by then I will mark it broken.

Eveeifyeve avatar Nov 13 '25 04:11 Eveeifyeve