Home Download Buy Blog Forum Support

Massive CPU usage from set_timeout

Massive CPU usage from set_timeout

Postby coderanger on Mon Mar 14, 2011 9:43 pm

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. http://paste.pocoo.org/show/353706/ has the full sample output if it helps.
coderanger
 
Posts: 4
Joined: Mon Mar 14, 2011 8:36 pm

Re: Massive CPU usage from set_timeout

Postby theblacklion on Mon Mar 14, 2011 11:23 pm

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.
theblacklion
 
Posts: 67
Joined: Sat Feb 05, 2011 10:07 pm
Location: Hannover, Germany

Re: Massive CPU usage from set_timeout

Postby jps on Mon Mar 14, 2011 11:59 pm

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.
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: Massive CPU usage from set_timeout

Postby coderanger on Sun Mar 20, 2011 3:14 am

Definitely seeing a change, but the issue persists. A new sample from 2051 is up at http://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.
coderanger
 
Posts: 4
Joined: Mon Mar 14, 2011 8:36 pm

Re: Massive CPU usage from set_timeout

Postby jps on Sun Mar 20, 2011 3:40 am

What plugins do you have installed?
jps
Site Admin
 
Posts: 3071
Joined: Wed Mar 19, 2008 12:33 pm

Re: Massive CPU usage from set_timeout

Postby coderanger on Sun Mar 20, 2011 4:26 am

The SublimeLint and two I wrote myself (https://github.com/coderanger/sublime-plugins). Almost certainly mine that are causing the issues.
coderanger
 
Posts: 4
Joined: Mon Mar 14, 2011 8:36 pm

Re: Massive CPU usage from set_timeout

Postby aroberge on Sun Mar 20, 2011 1:06 pm

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

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.
aroberge
 
Posts: 21
Joined: Sat Feb 12, 2011 1:03 am

Re: Massive CPU usage from set_timeout

Postby coderanger on Sun Mar 20, 2011 10:37 pm

I disabled my two plugins and the CPU usage did not climb back up.
coderanger
 
Posts: 4
Joined: Mon Mar 14, 2011 8:36 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 24 guests