mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
fe8ee9c43a
feat: add the ability to limit the number of threads launched by `main_loop` ## Motivation `main_loop` defaults to launch as many threads as cpus in one machine. When developing on multi-core remote servers on multiple projects, this will lead to thousands of idle threads being created. This is very annoying when one wants check whether his program under developing is running correctly via `htop`. <img width="756" alt="image" src="https://user-images.githubusercontent.com/41831480/206656419-fa3f0dd2-e554-4f36-be1b-29d54739930c.png"> ## Contribution This patch introduce the configuration option `rust-analyzer.numThreads` to set the desired thread number used by the main thread pool. This should have no effects on the performance as not all threads are actually used. <img width="1325" alt="image" src="https://user-images.githubusercontent.com/41831480/206656834-fe625c4c-b993-4771-8a82-7427c297fd41.png"> ## Demonstration The following is a snippet of `lunarvim` configuration using my own build. ```lua vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" }) require("lvim.lsp.manager").setup("rust_analyzer", { cmd = { "env", "RA_LOG=debug", "RA_LOG_FILE=/tmp/ra-test.log", "/home/jlhu/Projects/rust-analyzer/target/debug/rust-analyzer", }, init_options = { numThreads = 4, }, settings = { cachePriming = { numThreads = 8, }, }, }) ``` ## Limitations The `numThreads` can only be modified via `initializationOptions` in early initialisation because everything has to wait until the thread pool starts including the dynamic settings modification support. The `numThreads` also does not reflect the end results of how many threads is actually created, because I have not yet tracked down everything that spawns threads. |
||
---|---|---|
.. | ||
dev | ||
user |