Code Monkey home page Code Monkey logo

Comments (15)

tychoish avatar tychoish commented on August 26, 2024

I'not exactly seen this problem, though 3% CPU doesn't strike me as being terribly problematic, and I regularly see emacs sessions that are "doing things" as taking <10% CPU) To be fair, at least at the moment, all of my computers are both old (but have pretty beefy CPUs?), I don't know if this impacts you.

I'm currently noticing that emacs sessions tend to have ballooning memory usage, I think related to lsp-modeand I can provoke a CPU spike by calling (garbage-collect). Having said that I'm not positive that its lsp mode. I pushed a change in the past couple of days, 4175d67, that should increase the frequency of GC runs during damon startup. In general the logic is, "disable the garbage collector when you want fast performance, as in during startup, but decrease it when you want to avoid a memory spike, as the heap space won't return to the OS/etc, and if there's too much garbage to collect than the GC will take too long to run.)

I guess my questions are:

  • What version of emacs are you running? What operating system is it running on?
  • How big, in terms of bytes and lines, are the org buffers that you have open?
  • Are you running anything else (mu4e, erc, etc.)
  • Are you using lsp mode (python, golang, java/typescript?) for anything? or have buffers where that might be in use?
  • Are you using the submodule with the elpa cache?
  • Are you running as a daemon?

Let me think some more on this too. My gut says that the memory use and CPU weirdness are related, but I'm not sure. I'm pretty sure that there's nothing in the config that should cause either spike, but I do want to get to the bottom of this.

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

I'm running on a laptop with an i7-4600U CPU, using Ubuntu 20.04, upgrade from 18.04.

It's Emacs version: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian
user-error: Minibuffer window is not active

When I run my previous Emacs config there's no CPU load when I'm not using Emacs.

Here's an illustration of that:

# Example CPU data running my normal Emacs config
$ LC_NUMERIC=C.UTF_8 pidstat -dru -hl -p $(pgrep emacs),$(pgrep -d, -P $(pgrep emacs)) 10 60 

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:35:07     1001    276370    0.10    0.00    0.00    0.00    0.10     3      0.00      0.00  745812   71436   0.89      0.00      0.00      0.00       0  /usr/bin/emacs 

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:35:17     1001    276370    0.20    0.00    0.00    0.00    0.20     0      0.00      0.00  745812   71436   0.89      0.00      0.00      0.00       0  /usr/bin/emacs 

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:35:27     1001    276370    0.00    0.00    0.00    0.00    0.00     1      0.00      0.00  745812   71436   0.89      0.00      0.00      0.00       0  /usr/bin/emacs 

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:35:37     1001    276370    0.00    0.00    0.00    0.00    0.00     0      0.00      0.00  745812   71436   0.89      0.00      0.00      0.00       0  /usr/bin/emacs 
^C


# Example CPU data running your Emacs config
$ LC_NUMERIC=C.UTF_8 pidstat -dru -hl -p $(pgrep emacs),$(pgrep -d, -P $(pgrep emacs)) 10 60 
Linux 5.4.0-42-generic (ley-Latitude-E7440) 	2020-08-27 	_x86_64_	(4 CPU)

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:39:45     1001    276451    1.00    0.20    0.00    0.10    1.20     0      0.00      0.00  845008  169704   2.11      0.00      0.00      0.00       0  /usr/bin/emacs 
20:39:45     1001    276487    0.00    0.00    0.00    0.00    0.00     3      0.00      0.00   24652    5732   0.07      0.00      0.00      0.00       0  /usr/bin/aspell -a -m -B --encoding=utf-8 --sug-mode=ultra --run-together 

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:39:55     1001    276451    2.00    0.20    0.00    0.10    2.20     3      0.00      0.00  845008  169704   2.11      0.00      0.00      0.00       0  /usr/bin/emacs 
20:39:55     1001    276487    0.00    0.00    0.00    0.00    0.00     3      0.00      0.00   24652    5732   0.07      0.00      0.00      0.00       0  /usr/bin/aspell -a -m -B --encoding=utf-8 --sug-mode=ultra --run-together 

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  minflt/s  majflt/s     VSZ     RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
20:40:05     1001    276451    2.30    0.10    0.00    0.00    2.40     2      0.00      0.00  845008  169704   2.11      0.00      0.00      0.00       0  /usr/bin/emacs 
20:40:05     1001    276487    0.00    0.00    0.00    0.00    0.00     3      0.00      0.00   24652    5732   0.07      0.00      0.00      0.00       0  /usr/bin/aspell -a -m -B --encoding=utf-8 --sug-mode=ultra --run-together 

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

The three files I had/have open are very small - less than 200 lines in total, and nothing complicated at all.

When I only start Emacs, the %CPU stays small, until I open e.g. a text file with just two lines of text.
Then, once I've moved the cursor around, I see 2-3% CPU load.

I don't think I'm using the daemon.

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

I just did a 'git pull' and I still have the same behaviour. However, I did notice that if I do this sequence:

  • Start Emacs
  • Open simple text file
  • Move focus away from Emacs
    Then I have 0% CPU.
    If I now put focus back on Emacs, move the cursor a little in the text buffer, and then move focus away from Emacs, then Emacs continues to use 2-3 %CPU.

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

Interesting, the function tychoish-setup-global-modes which is called near the end of init.el and is implemented in conf/local-functions.el starts a bunch of global modes. That could totally be a cause of the issue. Eyeballing it now, none of these (other than daemon) could really have the impact, but it'd be interesting to see if commenting out this function call, and maybe narrowing it down would help identify the culprit.

My second theory is that, in an odd wrinkle, the projectile configuration which loads on a timer, is actually responsible for the background process. That configuration is here: https://github.com/tychoish/.emacs.d/blob/main/conf/programming.el#L316, and you can test this theory out by: commenting out the (projectile-mode +1) call at the end, and/or the :defer 1 argument and seeing if you see

If we know what the flaw is, I'm more than happy to add a flag that loads whatever the culprit is conditionally, and thanks so much for doing this debugging work yourself!

Cheers,
sam

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

I tested commenting out the three last lines in init.el, i.e.:

(tychoish-setup-global-modes)
(tychoish-setup-modeline)
(tychoish-setup-user-local-config)

But it didn't help. It also seems that moving out of focus doesn't necessarily reduce the CPU load after just having opened a simple text file.

Then I restored the three lines above and instead removed (commented out) the (projectile-mode +1).
It's perhaps behaving slightly better, but it seems that something in Emacs "wakes up" after a few seconds and starts consuming CPU again. See below at 21:33:41 where I'm de-focusing Emacs, and %CPU goes down, but then at 21:33:59 the %CPU comes back again:

$ emacs ~/emacs-test.txt & LC_NUMERIC=C.UTF_8 pidstat -u -hl -p $(pgrep emacs),$(pgrep -d, -P $(pgrep emacs)) 2

<snipped a number of lines>

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
21:32:59     1001    278179    0.50    0.00    0.00    0.50    0.50     2  emacs emacs-test.txt 
21:33:01     1001    278179    1.00    0.00    0.00    0.00    1.00     1  emacs emacs-test.txt 
21:33:03     1001    278179    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:33:05     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:07     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:09     1001    278179    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:33:11     1001    278179    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:33:13     1001    278179    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:33:15     1001    278179    0.50    0.00    0.00    0.00    0.50     0  emacs emacs-test.txt 
21:33:17     1001    278179    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:33:19     1001    278179    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:33:21     1001    278179    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:33:23     1001    278179    1.00    0.00    0.00    0.00    1.00     1  emacs emacs-test.txt 
21:33:25     1001    278179    2.50    0.00    0.00    0.00    2.50     0  emacs emacs-test.txt 
21:33:27     1001    278179    1.00    0.50    0.00    0.00    1.50     0  emacs emacs-test.txt 
21:33:29     1001    278179    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:33:31     1001    278179    0.50    0.00    0.00    0.00    0.50     3  emacs emacs-test.txt 
21:33:33     1001    278179    0.50    0.00    0.00    0.00    0.50     0  emacs emacs-test.txt 
21:33:35     1001    278179    1.00    0.00    0.00    0.00    1.00     3  emacs emacs-test.txt 
21:33:37     1001    278179    0.50    0.00    0.00    0.00    0.50     0  emacs emacs-test.txt 
21:33:39     1001    278179    0.50    0.00    0.00    0.00    0.50     3  emacs emacs-test.txt 
21:33:41     1001    278179    1.00    0.00    0.00    0.50    1.00     1  emacs emacs-test.txt 
21:33:43     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:45     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:47     1001    278179    0.00    0.00    0.00    0.00    0.00     3  emacs emacs-test.txt 
21:33:49     1001    278179    0.00    0.00    0.00    0.00    0.00     3  emacs emacs-test.txt 
21:33:51     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:53     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:55     1001    278179    0.00    0.00    0.00    0.00    0.00     1  emacs emacs-test.txt 
21:33:57     1001    278179    0.00    0.00    0.00    0.00    0.00     3  emacs emacs-test.txt 
21:33:59     1001    278179    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:34:01     1001    278179    0.50    0.00    0.00    0.00    0.50     3  emacs emacs-test.txt 
21:34:03     1001    278179    1.00    0.00    0.00    0.00    1.00     3  emacs emacs-test.txt 
21:34:05     1001    278179    0.00    0.50    0.00    0.00    0.50     3  emacs emacs-test.txt 
21:34:07     1001    278179    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:34:09     1001    278179    1.00    0.00    0.00    0.00    1.00     3  emacs emacs-test.txt 
21:34:11     1001    278179    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 

Finally I tested uncommenting the three lines in init.el as well and repeating a test. The command line below starts Emacs and measures CPU load. After Emacs has started, at 21:40:08 I move the cursor away from Emacs so focus is on the terminal. Then at 21:40:22 a small CPU load comes back.

$ (cd ~; emacs emacs-test.txt) & LC_NUMERIC=C.UTF_8 pidstat -u -hl -p $(pgrep emacs),$(pgrep -d, -P $(pgrep emacs)) 2
[1] 278332
Linux 5.4.0-42-generic (ley-Latitude-E7440) 	2020-08-27 	_x86_64_	(4 CPU)

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
21:39:50     1001    278334   79.00   10.50    0.00    1.50   89.50     0  emacs emacs-test.txt 
21:39:52     1001    278334   14.00    1.00    0.00    0.00   15.00     0  emacs emacs-test.txt 
21:39:54     1001    278334    0.50    0.00    0.00    0.50    0.50     0  emacs emacs-test.txt 
21:39:56     1001    278334    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:39:58     1001    278334    1.00    0.00    0.00    0.00    1.00     1  emacs emacs-test.txt 
21:40:00     1001    278334    0.00    0.50    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:40:02     1001    278334    1.00    0.00    0.00    0.00    1.00     0  emacs emacs-test.txt 
21:40:04     1001    278334    0.50    0.00    0.00    0.00    0.50     3  emacs emacs-test.txt 
21:40:06     1001    278334    1.00    1.00    0.00    0.00    2.00     0  emacs emacs-test.txt 
21:40:08     1001    278334    0.00    0.00    0.00    0.00    0.00     0  emacs emacs-test.txt 
21:40:10     1001    278334    0.00    0.00    0.00    0.00    0.00     0  emacs emacs-test.txt 
21:40:12     1001    278334    0.00    0.00    0.00    0.00    0.00     0  emacs emacs-test.txt 
21:40:14     1001    278334    0.00    0.00    0.00    0.00    0.00     0  emacs emacs-test.txt 
21:40:16     1001    278334    0.00    0.00    0.00    0.00    0.00     3  emacs emacs-test.txt 
21:40:18     1001    278334    0.00    0.00    0.00    0.00    0.00     3  emacs emacs-test.txt 
21:40:20     1001    278334    0.00    0.00    0.00    0.00    0.00     2  emacs emacs-test.txt 
21:40:22     1001    278334    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:40:24     1001    278334    0.50    0.00    0.00    0.00    0.50     0  emacs emacs-test.txt 
21:40:26     1001    278334    0.50    0.00    0.00    0.00    0.50     0  emacs emacs-test.txt 
21:40:28     1001    278334    0.50    0.50    0.00    0.00    1.00     0  emacs emacs-test.txt 
21:40:30     1001    278334    0.50    0.00    0.00    0.00    0.50     1  emacs emacs-test.txt 
21:40:32     1001    278334    0.00    0.00    0.00    0.00    0.00     0  emacs emacs-test.txt 
21:40:34     1001    278334    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:40:36     1001    278334    0.50    0.00    0.00    0.00    0.50     2  emacs emacs-test.txt 
21:40:38     1001    278334    2.50    0.00    0.00    0.00    2.50     3  emacs emacs-test.txt 
21:40:40     1001    278334    0.50    0.00    0.00    0.00    0.50     3  emacs emacs-test.txt 
21:40:42     1001    278334    0.50    0.00    0.00    0.00    0.50     3  emacs emacs-test.txt 

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

I'd see if you can get the behavior you're looking at without opening any files, and if you cannot, I'd start looking at the configuration of the modes that are active in those files.

Though I'm sure its of little consolation to you, I'm somewhat gratified that it looks like projectile and the various minor modes I've collected are not to blame.

My next idea is to look at the output of M-x list-timers, which should tell you what's running periodically in the background. My leading suspicion is that it's something like helm-ff-cache or auto-revert-mode or something similar (you can turn off helm-ff-cache, similarly, perhaps for auto-revert-mode and I'm happy to leave it disabled by default, if this is the case.) You can also disable things specifically by running cancel-function-timers which you can use to disable things that are running in the background, though you'll probably have to do some manual trial and error to find the culprit.

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

I just now tested not opening a simple text file. Instead, once Emacs had started I did 'C-x b some-buffer.txt' to switch into another buffer. I then moved the focus away from Emacs at 07:18:10, at which %CPU soon goes to 0, but then at 07:18:28 it goes up again. Without me having put focus back on Emacs. Or even typed anything into the buffer window for that.

So I think I'll stop troubleshooting at this point, as my intention anyway only intended to check out your configuration.
I hope you're able to reproduce the behaviour on your side. If you can't and would like me to do some short tests, just ask.

cheers,
Christian

$ emacs & LC_NUMERIC=C.UTF_8 pidstat -u -hl -p $(pgrep emacs),$(pgrep -d, -P $(pgrep emacs)) 2
[1] 281890
Linux 5.4.0-42-generic (ley-Latitude-E7440) 	2020-08-28 	_x86_64_	(4 CPU)

# Time        UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
07:17:56     1001    281890   42.50    6.00    0.00    1.00   48.50     2  emacs 
07:17:58     1001    281890   12.50    2.00    0.00    0.50   14.50     3  emacs 
07:18:00     1001    281890   20.50    2.00    0.00    0.00   22.50     3  emacs 
07:18:02     1001    281890   29.00    1.50    0.00    0.50   30.50     3  emacs 
07:18:04     1001    281890    1.00    0.00    0.00    0.00    1.00     3  emacs 
07:18:06     1001    281890    0.50    0.00    0.00    0.00    0.50     1  emacs 
07:18:08     1001    281890    0.50    0.00    0.00    0.00    0.50     2  emacs 
07:18:10     1001    281890    0.50    0.00    0.00    0.00    0.50     0  emacs 
07:18:12     1001    281890    0.50    0.50    0.00    0.00    1.00     0  emacs 
07:18:14     1001    281890    2.00    0.00    0.00    0.00    2.00     1  emacs 
07:18:16     1001    281890    0.00    0.00    0.00    0.00    0.00     0  emacs 
07:18:18     1001    281890    0.00    0.00    0.00    0.00    0.00     0  emacs 
07:18:20     1001    281890    0.00    0.00    0.00    0.00    0.00     0  emacs 
07:18:22     1001    281890    0.00    0.00    0.00    0.00    0.00     0  emacs 
07:18:24     1001    281890    0.00    0.00    0.00    0.00    0.00     0  emacs 
07:18:26     1001    281890    0.00    0.00    0.00    0.00    0.00     1  emacs 
07:18:28     1001    281890    0.50    0.00    0.00    0.00    0.50     2  emacs 
07:18:30     1001    281890    0.50    0.00    0.00    0.00    0.50     3  emacs 
07:18:32     1001    281890    0.00    0.50    0.00    0.00    0.50     2  emacs 
07:18:34     1001    281890    2.50    0.00    0.00    0.00    2.50     0  emacs 
07:18:36     1001    281890    0.50    0.00    0.00    0.00    0.50     3  emacs 
07:18:38     1001    281890    0.50    0.00    0.00    0.00    0.50     0  emacs 
^C

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

Sorry it didn't work out, I'm not seeing anything like this on my end.

My only curiosity from my last question that is unanswered is: were any of the background timer functions to blame from running 'list-timers`?

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

I'm not sure how to use 'list-timers', it says it's disabled? I pressed 'space' and hopefully it ran anyway:

   *       0.05        t jit-lock-deferred-fontify
   *       0.50        t jit-lock-context-fontify
   *      11.51        - helm-ff--cache-mode-refresh

I then ran it again and got:

           0.35     0.01 blink-cursor-timer-function
           6.59        - undo-auto--boundary-timer
   *       0.05        t jit-lock-deferred-fontify
   *       0.50        t jit-lock-context-fontify
   *       0.50  :repeat blink-cursor-start
   *       1.50        - helm-ff--cache-mode-refres

I tried cancelling timers (not sure if I did it correctly), but it didn't seem to have an effect.

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

Ah yes, I managed to reproduced it: I think if you do the following:

(setq undo-auto-current-boundary-timer t)
(helm-ff-cache-mode 0)
(show-paren-mode 0)

you should be able to kill all of the timers which drops the idle CPU use to 0; I'm going to push something to remove them, and then I'll, (later) add something to enable them optionally.

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

The commit to disable these modes/operations is committed, I'll try and find a way to enable them more safely later.

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

I've pushed a second commit that turns down the nobs on a lot of the timers down to a reasonable level which shouldn't impact the CPU anymore. Let me know if this helps!

from .emacs.d.

DrChr avatar DrChr commented on August 26, 2024

I am glad you managed to reproduce it, it sucks trying to troubleshoot when you can't reproduce locally.

After a 'git pull', my test case is now behaving just fine w.r.t. %CPU - thank you very much for the fix!

I'll continue using/testing your config for a while longer and I'll let you know if I see any other indication of CPU loading.

from .emacs.d.

tychoish avatar tychoish commented on August 26, 2024

Thanks for all of the feedback and support! It's been a great help (and great fun) to improve things. I look forward to hearing more from you in the future! Let me know if there are other usability improvements: this config is pretty well organized and polished, but if there are really weird parts, I've definitely gotten used to them over the past (many) years, so extra eyes are totally worthwhile.

Cheers!

from .emacs.d.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.