mirror of
https://github.com/neovim/neovim.git
synced 2025-09-04 02:18:15 +00:00
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).
(cherry picked from commit f9ce939bf5
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
d31953d532
commit
4c8486e1f2
@@ -190,6 +190,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
|
||||
|
@@ -39,6 +39,10 @@
|
||||
# include "nvim/fileio.h"
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
# include <mach/task.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE__NSGETENVIRON
|
||||
# include <crt_externs.h>
|
||||
#endif
|
||||
@@ -352,6 +356,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.
|
||||
|
Reference in New Issue
Block a user