neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit f9ce939bf53b84f7e6e4ecca3875dd0c378991db
parent 1ae09bf54560ab9a060972012bcb0ebccff52978
Author: Luna Razzaghipour <luna@xoria.org>
Date:   Wed,  3 Sep 2025 11:34:46 +1000

perf: scheduler priority clamping on macOS #35488

Problem:
All of Nvim’s threads are clamped to the Default QoS class. This means
that Nvim is forced to compete for CPU time with compilers and other
batch work, and is even prioritized beneath user-initiated work in GUI
apps like e.g. file imports. This significantly harms responsiveness.

Solution:
Tell the kernel that the Nvim process takes part in rendering a UI.

Implementation:
Remove the process-wide QoS clamp. This doesn’t directly do anything to
the main thread, but rather has the side-effect of letting the main
thread run at its actual QoS (User Interactive QoS).
Diffstat:
Msrc/nvim/main.c | 1+
Msrc/nvim/os/env.c | 16++++++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/nvim/main.c b/src/nvim/main.c @@ -188,6 +188,7 @@ static bool event_teardown(void) /// Needed for unit tests. void early_init(mparm_T *paramp) { + os_hint_priority(); estack_init(); cmdline_init(); eval_init(); // init global variables diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c @@ -39,6 +39,10 @@ # include "nvim/fileio.h" #endif +#ifdef __APPLE__ +# include <mach/task.h> +#endif + #ifdef HAVE__NSGETENVIRON # include <crt_externs.h> #endif @@ -367,6 +371,18 @@ int64_t os_get_pid(void) #endif } +/// Signals to the OS that Nvim is an application for "interactive work" +/// which should be prioritized similar to a GUI app. +void os_hint_priority(void) +{ +#ifdef __APPLE__ + // By default, processes have the TASK_UNSPECIFIED "role", which means all of its threads are + // clamped to Default QoS. Setting the role to TASK_DEFAULT_APPLICATION removes this clamp. + integer_t policy = TASK_DEFAULT_APPLICATION; + task_policy_set(mach_task_self(), TASK_CATEGORY_POLICY, &policy, 1); +#endif +} + /// Gets the hostname of the current machine. /// /// @param hostname Buffer to store the hostname.