Why does texmacs use cpu resources when idle?

I have noticed that texmacs continues to use cpu resources when it is idle. Here’s a screenshot:

image

Usually none of my other applications running in the background use an cpu resources. Is there any way to mitigate this?

Here’s a screenshot from another system monitor app:

Apparently, no one is facing this issue.

TeXmacs do some regular polling and event handling. I’m not sure if what you observe is abnormal, sometime we saw that Qt has different behaviour in different systems. On my Mac I do not see any abnormal CPU use, even when idle. Even from your screenshot one could see that firefox or thunderbird also use some resources, probably to do some polling too. Which version of TeXmacs are you using and on which distribution?

True, but that’s because these applications are connected to the internet and need to constantly update their state. Meanwhile, all my other text editors consume ~0% CPU when idle. Opening texamcs with a blank document and doing nothing consume 1%. While 1% might not much, by texmacs is consuming CPU resources while doing absolutely nothing. Here’s another screenshot just now.

What’s even crazier is that I have a windows vm idling in the background consumes 0% cpu, whereas texmacs doesn’t.

I have to agree that TeXmacs consumes a bit more resources than might be expected. An idling Atom consumes about 0.1%, while TeXmacs hovers around 0.3%. This is on Fedora with Wayland with Qt 5.15.2. You could try to do some profiling if you want to get to the bottom of this.

2 Likes

We do some polling because of the way the TeXmacs to/from Qt boundary is organised. It could be that we run timers too often, or that some caching is going wrong and we regenerate menus even if not needed, I need to investigate. Thanks to both for the heads up. It might be useful also to report to the texmacs-dev list to make Joris aware of this or file a bug report. I agree that we should not be more resource-intesinve that an idle Electron instance.

2 Likes

On the Mac the situation seems ok:

but if I activate TeXmacs activity raises to ~4% for 30 sec or so to drop again later

1 Like

This pull request will help reduce the CPU usage.

edit_interface_rep::apply_changes contribute the most CPU usage when TeXmacs is idle.

1 Like

Could you possibly include an appimage for those of us that are on linux ?

Thanks for the feedback @darcy. Unfortunately the patch doesn’t seem to make a difference for me.

I believe @darcy has some plans to automate building from the git repo. This would be a great feature, as we desperately need more testing before release (both of the main development branch and of an “unstable” branch with community contributions).

it reduce the CPU usage theoretically. But it might not be the most CPU-intensive code.

Here is the second pull request to reduce the CPU usage:

We change the title only when the document tree is changed.

The installation of Mogan Editor on GNU/Linux is much more easy than GNU TeXmacs. You can compile by yourself. No need to install gnu guile 1.8.x first.

If you are using debian, just ./packages/debian/package.sh and install the required deps please.

Is the process the same for arch?

no, please use cmake by yourself

This seems to be the case. I use top to check CPU usage, and in the idle status, texmacs.bin comsumes about 3%, even more significant than the OP.

I use gdb to attach texmacs.bin, and get backtrace from time to time, which looks like

(gdb) bt
#0  0x00007fab39c6f3ff in poll () from /usr/lib/x86_64-linux-gnu/libc.so.6
#1  0x00007fab3928b0ae in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007fab3928b1cf in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#3  0x00007fab3a55c51f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#4  0x00007fab3a50398b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#5  0x00007fab3a50bc00 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#6  0x000055e9b4db3761 in ?? ()
#7  0x000055e9b5c00b00 in ?? ()

I did not build texmacs myself therefore there is no debug symbol for ??.

Many thanks for this @darcy. I’m afraid this also didn’t make much of a difference for me.

Any updates on this issue? Texmacs consumes ~1% when doing absolutely nothing!