Home Download Buy Blog Forum Support

Why is Sublime using significant CPU when idle?

Why is Sublime using significant CPU when idle?

Postby datihein on Sat Aug 17, 2013 6:44 pm

On my Mac (OS X 10.8.4) running Sublime Text 3 (build 3047), I see a base load of a little more than 6% CPU when Sublime is running but I'm not typing or scrolling.

I see the same 6-7% CPU whether I have any 3rd party packages installed or not. The packages I use don't seem to have any impact on CPU usage.

I expect a text editor to consume very close to 0% (zero) CPU when not interacting with the user. Why does it matter? Laptop battery life is why it matters.

--
Dave Hein
datihein
 
Posts: 12
Joined: Sun Jul 29, 2012 6:20 pm

Re: Why is Sublime using significant CPU when idle?

Postby wuub on Sat Aug 17, 2013 8:47 pm

Probably indexing your code for Goto Anything (Ctrl+Shift+R).
This is a one time thing, but can take a while if you added a big codebase to project.

With exactly the same setup I'm seeing 0% CPU utilisation when idling
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Why is Sublime using significant CPU when idle?

Postby datihein on Thu Aug 22, 2013 11:04 pm

wuub,

I don't think it's indexing any code. I have only about a dozen files in my project, mostly python with a few shell scripts and .gitconfig. Unless it's trying to index the git repo under .git, but even that is really small. And I've let it run for hour, overnight, and it still is sucking about 6% CPU.

:-(

UPDATE: It turns out that the problem is indexing, but in an interesting way. See my two posts dated 29 August, below. The specific problem is identified and a workaround is offered.

--
Dave
Last edited by datihein on Thu Aug 29, 2013 1:11 pm, edited 1 time in total.
datihein
 
Posts: 12
Joined: Sun Jul 29, 2012 6:20 pm

Re: Why is Sublime using significant CPU when idle?

Postby qgates on Fri Aug 23, 2013 1:29 am

It's not likely down to indexing which, as wuub points out, should stop after a short time. Other thoughts:

1. Plugins could be responsible. Try disabling all your plugins temporarily to see if that fixes the problem. If it does, bring them in one by one until you find the offending plugin.

2. If you're using a laptop with particularly aggressive power saving. Say your quad-core puppy runs at 3Ghz clock, but an aggressive power saving scheme downclocks the system to 400hz, or turns off some of the cores, or both - when it deems the system to be "idle". In that case, processes using a tiny bit of CPU will actually look like they're using a lot more, since 6% of 400hz is <1% of 3Ghz. Try putting your laptop into max performance profile and see what the CPU use is then.

Personally I don't see sublime doing much of anything when idle. Rarely do I see anything other than 0 on the sublime process. If you're editing particularly large files, or editing across a network, this could also have a minor impact on CPU as sublime will "poll" files and/or swap stuff in and out.

If you've no plugins enabled and no files loaded and still seeing 6%, well, you got me.. Perhaps there's something Mac-specific going on here, as I use Sublime only on Linux and Windows.
qgates
 
Posts: 205
Joined: Mon Nov 05, 2012 4:33 pm

Re: Why is Sublime using significant CPU when idle?

Postby datihein on Fri Aug 23, 2013 11:06 pm

OK, I've narrowed down the problem.

If I start Sublime Text clean -- no files, folders, or projects open (i.e., I closed out of everything before shutting down), then:

1. As long as I only open individual files -- as long as I never open a project and never open a folder/directory -- then the CPU hovers at around 0.2%.

2. But as soon as I open a directory/folder or I open a folder, then Sublime Text shoots up to 6% CPU and stays there ... even if I subsequently close all open files and close the project/directory window. I have to kill the application and re-open it (clean) to get back to 0% (or very close to 0%) CPU.

This behavior exists with or without the few packages I use installed.

--
Dave
datihein
 
Posts: 12
Joined: Sun Jul 29, 2012 6:20 pm

Re: Why is Sublime using significant CPU when idle?

Postby datihein on Thu Aug 29, 2013 12:48 pm

OK, as suggested earlier in this thread, this problem is a re-indexing issue on OS X. It seems to be unrelated to the type or quantity of files being indexed.

I don't know what SublimeText3 is indexing, but it is indexing something over-and-over-and-over-again. Even if there are only a very few files in the project/directory-tree, the indexing occurs continuously and repeatedly. The only way to avoid this is to avoid opening a directory or project.

I'd really like to see this OS X issue resolved. :-(

Here's a trace using 'opensnoop' on my Mac: These lines are output rapidly:

Code: Select all
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000625.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000626.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000627.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000628.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000629.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index
q  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst
  503   7819 Sublime Text  24 /Users/datihein/Library/Application Support/Sublime Text 3/Index/000630.sst


--
Dave Hein
datihein
 
Posts: 12
Joined: Sun Jul 29, 2012 6:20 pm

Re: Why is Sublime using significant CPU when idle?

Postby datihein on Thu Aug 29, 2013 1:07 pm

More info, and a workaround ...

I looked in to the Index directory, as identified by opensnoop (see my previous post), and found a LOG file with these log entries (a new block of entries every second):

Code: Select all
2013/08/29-06:52:24.942541 10f699000 Compacting 19@0 + 3@1 files
2013/08/29-06:52:26.742562 10f699000 compacted to: files[ 19 5 0 0 0 0 0 ]
2013/08/29-06:52:26.742723 10f699000 Delete type=2 #400
2013/08/29-06:52:26.743659 10f699000 Compaction error: IO error: /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst: Invalid argument
2013/08/29-06:52:26.743692 10f699000 Waiting after background compaction error: IO error: /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst: Invalid argument
2013/08/29-06:52:27.744794 10f699000 Compacting 19@0 + 3@1 files
2013/08/29-06:52:27.855327 10f699000 compacted to: files[ 19 5 0 0 0 0 0 ]
2013/08/29-06:52:27.855470 10f699000 Delete type=2 #401
2013/08/29-06:52:27.944136 10f699000 Compaction error: IO error: /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst: Invalid argument
2013/08/29-06:52:27.944185 10f699000 Waiting after background compaction error: IO error: /Users/datihein/Library/Application Support/Sublime Text 3/Index/000062.sst: Invalid argument


On a hunch, I shutdown ST3 and renamed the Index directory to Index.save and then created a new, emtpy, Index directory. Then I restarted ST3 and now it idles along at 0.2% CPU. Much better.

So there is some kind of defect in the code that isn't handling an error condition properly, causing the indexing to restart after the error. Repeat ad naseum.

FYI, the file it complains about -- 000062.sst -- is a zero-length file, dated a few months ago.

Bottom line: there is a bug in error handling in the indexing, but you can workaround the bug by clearing out the Index directory if you notice ST3 consuming a lot of CPU when idle for a long time (many minutes).
datihein
 
Posts: 12
Joined: Sun Jul 29, 2012 6:20 pm

Re: Why is Sublime using significant CPU when idle?

Postby darcybrown on Wed Oct 23, 2013 8:03 pm

BIG thanks on that workaround! This was making my fan kick on and drive me insane.
darcybrown
 
Posts: 1
Joined: Wed Oct 23, 2013 7:27 pm

Re: Why is Sublime using significant CPU when idle?

Postby farfromrefuge on Thu Oct 24, 2013 9:41 am

thanks for the workaround!!!

But we need a fix :s
farfromrefuge
 
Posts: 38
Joined: Mon Oct 19, 2009 11:49 am

Re: Why is Sublime using significant CPU when idle?

Postby corradomatt on Wed Nov 20, 2013 12:47 am

I'm having the exact same issue on windows 7 and build 3047 of ST3. Whenever I open a project, my cpu usage eventually jumps to 100% and stays there until I shut down ST3. This makes ST3 virtually unusable. This just started happening today. I'm on a trial account currently with ST3 and have plans to purchase the software but this makes me worried.
corradomatt
 
Posts: 2
Joined: Wed Nov 20, 2013 12:43 am

Next

Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 23 guests