Sublime Forum

High CPU Usage on File Save

#1

Hi,
Recently I started to notice whenever I hit Ctrl + S to save file, sublime 3 UI/Editor will freezer for a couple seconds during which I basically cannot do anything. Further checking reveals during this freezing time, CPU usage by sublime rises to 30%+.Because of this, for the time being, I have switch of VSCode. Still I would love to continue to use sublime if this can be solved.

I mostly use sublime for Laravel based PHP/HTML/JavaScript project, don’t consider my project large. I have followed every post with similar issues, checked my index_exclude_patterns, binary file pattern, fresh installation etc. none of them seems to solve my problem.

Thanks in advance.

Update: the high CPU usage thing stopped after I set “index_files”: false. So the problem is definitely somehow related to indexing.

0 Likes

#2

Do you have an example file that causes the issue?

Have you tried reverting to a fresh state? https://www.sublimetext.com/docs/3/revert.html

0 Likes

#3

Hi Wbond,

thanks for your reply. I just reproduced the issue with the following repo:

Steps to reproduce:

  1. Download the repo
  2. Unzip and cd into folder
  3. Open the folder with ST3. It will several minutes to index.
  4. Open a random file, and type something somewhere, then hit Ctrl + S
  5. Observe CPU usage by ST3 in task manager. The usage usually stays high for several to 10+ seconds.

Yes, I tried with fresh installation either by deleting the data folder, or download a portal version. The high CPU usage seems the same.

0 Likes

#4

FWIW, that directory opens imperceptibly instantly for me. I opened filemanager.php and it also saved instantly (even accounting for the fact that I had never compiled the PHP mode before).

My guess is you have some sort of plugin that is causing this.

1 Like

#5

@zhiyong do you see high cpu usage in sublime_text or plugin_host process?

0 Likes

#6

@djspiewak I had 3 plugins, vue syntax highlighter, docblocker, package management, with all these 3 removed, or a clean portable sublime text 3, it still takes minutes to index the above repo, and whenever I hit ctrl + s, there will several seconds of high CPU usage.
@rchl high CPU usage is in ST3 not plugin_host

0 Likes

#7

It could be your (auto) session file being very big. I recently had, what looks like a same issue, where my session file was 16MB big due to a lot of matches in “find in files” results open somewhere in the window.

0 Likes

#8

@rchl How do I fix the issue? Not completely understand the session thing. When I just tested, I have only one ST3 open, and don’t have Shift -Ctrl - F window open anywhere.

0 Likes

#9

Check size of your session file

0 Likes

#10

Just checked the session file, mine is a only 19k, after deleting it, I still have the high CPU usage issue. Not sure if it is my windows. I will try it on a clean Windows 10 installation, and see if that helps.

0 Likes

#11

Just tried it on a fresh installation of windows 10, portable ST3, got the same results. Not sure if it is relevant, I am having issues with sourcetree as well. I had to click on its icon in taskbar many times to bring the ui up, and I don’t see this with mechanic hard drive and otherwise the same machine.

Is it because my computer is too old? Like i5-3320m?

0 Likes

#12

Some further investigation:

The high CPU usage seems to happen only to php files. In the same repo, when I just hit Ctrl + S when inside other files like xml, json, etc. the problem doesn’t happen. Also when it happens, an extra ST3 process will show up in task manager for the duration of high CPU usage then disappear by itself.

This seems to be an old issue, really hope you guys can fix it.

0 Likes

#13

I think you’re actually seeing two tangentially related issues. Sublime Text performs saving in the foreground, ie. it blocks until saving has completed. If you have a spinning disk, network drive and/or use windows this can cause a noticeable pause. We’re planning to address this in a future update.

Sublime Text also updates the index in a background process(s) when a file changes on disk, this is likely the cause of the high cpu usage. The project you linked has over 10000 files in it due to the vendor directory. I would suggest adding that to your “folder_exclude_patterns” setting to make indexing faster, or if you’re not using it you can disable indexing completely with the “index_files” setting.

0 Likes

#14

The thing puzzles me is: 1) Build 3207 runs perfectly fine without such problem with the same project on Ubuntu 18.04; 2) The installation on windows was briefly fine for a few hours, then somehow the high cpu usage problem crept back again. 3) I didn’t notice such problem until earlier this year. It was problem there earlier but I just didn’t notice it. 4) Several persons claimed in this thread they didn’t see such problem. 5) Excluding vendor folder doesn’t help. 6) All 3 of my computers (two windows 10, one was freshly installed) and Ubuntu have SSD and otherwise the same hardware.

0 Likes

#15

Windows IO is significantly slower than linux hence why this issue is a lot more pronounced on windows. I see similar cpu spikes on save across linux and a guest windows vm, it would be longer on a slower cpu.

0 Likes

#16

Its great post and help me a lot. please keep continue posting .

0 Likes

#17

Using Windows, I am observing the same problems. Reindexing a large PHP project after saving a single file is much slower than in previous builds, hanging window switching and general responsiveness.

When I save a file, I see the indexing percentage read “0%” then jump to “99%” and then complete.

While it seems related to the indexing process since the build of ST3 has been the only change, I haven’t ruled out a different conflict that interacts with the PHP linting process.

0 Likes

#18

Hopefully they are not polling every file under the opened folder to look for changed file(s).

0 Likes