Skip to content

A read loop on macOS is using a lot of power/CPU #52

@jmataraz

Description

@jmataraz

Running on macOS, interfacing to clangd, I observe Emacs using a constant 20-80% CPU in Activity Monitor when LSPCE is loaded. I did an Instruments profile on it and found the LSPCE module thread using the majority of cpu time:

5.89 s 100.0% 0 s Emacs (98968)
5.64 s 95.7% 0 s Emacs 0x1b1de1a
5.64 s 95.7% 0 s thread_start
5.64 s 95.7% 0 s _pthread_start
5.64 s 95.7% 0 s std::sys::pal::unix::thread::Thread::new::thread_start::h44ebc83f14222f58
5.64 s 95.7% 0 s core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::hac316d3bc42e362a
5.64 s 95.7% 114.00 ms std::sys::backtrace::__rust_begin_short_backtrace::h991112f7bfe02ba3
5.40 s 91.6% 49.00 ms _$LT$std..process..ChildStderr$u20$as$u20$std..io..Read$GT$::read_buf::h03ed8e5e001ecc40
5.34 s 90.6% 817.00 ms read

That last read is to libsystem_kernel.dylib so that's where LSPCE leaves off.

I'm wondering if there's a difference in the read system call between macOS and Linux variants. Maybe it's non-blocking on macOS, for example, when there is no data available? I can collect more data if need be but I thought I'd open the issue in case you can identify the issue by inspection/analysis.

When I modify my startup init to not load LSPCE, CPU usage drops back down to 1-2%.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions