Sublime Forum

Massive CPU usage from set_timeout

#1

I’m using several plugins that use set_timeout to create a background-ish task (the function calls set_timeout(fn, 1000) where fn is the function itself). This seems to cause major CPU usage issues over time. At startup it isn’t a big deal, but if I leave the editor running for more than 30-45 minutes CPU goes through the roof. Sample shows that the vast majority of time is being spent running NSDelayedPerforms, which is why I suspect set_timeout (I might be entirely wrong there though). Is there a better way to handle this? It would be nice if there was an event callback which was just called every X seconds or frames, or just a recurring version of set_timeout. paste.pocoo.org/show/353706/ has the full sample output if it helps.

0 Likes

#2

This normally indicates that these plugins call themselves multiple times per round. I had this some minutes ago while writing a plugin using set_timeout and saving it multiple times. I’ve written a little workaround for detecting if a reload of the module has been done.
But I can also say that set_timeout seems to be really expensive on the CPU.

0 Likes

#3

Thanks for the detailed report - it seems the issue will arise whenever there is more than one periodic task running via set_timeout. It effects OSX and Linux, the Windows implementation doesn’t have the same flaw. I’ll fix it for the next version.

0 Likes

#4

Definitely seeing a change, but the issue persists. A new sample from 2051 is up at paste.pocoo.org/show/356436/. On my 2.4GHz Core 2 Duo MBP this is still using 50% of the CPU after a while. Not sure what the issue is, since I don’t see anything anomalous in the sample data.

0 Likes

#5

What plugins do you have installed?

0 Likes

#6

The SublimeLint and two I wrote myself (github.com/coderanger/sublime-plugins). Almost certainly mine that are causing the issues.

0 Likes

#7

If it is my version of the SublimeLint plugin, you can disable it via a preference setting (rather than having to uninstall it) and confirm that it is not the cause of the problem you see.

0 Likes

#8

I disabled my two plugins and the CPU usage did not climb back up.

0 Likes