0

Why do animated cursors drain the battery?

nh2 11 year бұрын 0

Using strace -f sublime_text on Linux, I noticed that Sublime spams poll() system calls when the window has focus and you use the smooth, phase, or blink caret_style:


[pid 20117] poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=11, events=POLLIN}, {fd=12, events=POLLIN}, {fd=14, events=POLLIN}, {fd=15, events=POLLIN}, {fd=18, events=POLLIN}, {fd=19, events=POLLIN}, {fd=13, events=POLLIN}, {fd=17, events=POLLIN}, {fd=6, events=POLLIN}], 11, 0) = 0 (Timeout)
[pid 20117] recvfrom(3, 0xdd2f94, 4096, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)


This results in a permanent 5% CPU usage and prevents the CPU from entering sleep modes and reducing battery life, even if you are not doing anything.


If you use the wide or solid carets, this does not happen.


Questions:

  1. Why needs poll() be used for caret animation?
  2. I can understand that smooth/phase require some form of frequent updates, but why does blink poll with the same frequency instead of twice per second?

Thank you!