Sublime Forum

[Solved] High CPU Usage in Beta 3124

#1

If you are experiencing heavy CPU usage with build 3124, try Beta 3126.


Below is a description of how indexing works and reasons you may see Sublime Text using your CPUs.

Sublime Text 3 includes background index workers that scan all source code in folders you have opened, which powers the functionality Goto Definition, Goto Symbol in Project and the Definitions popup. This indexing functionality is not new with build 3124.

When a new version of Sublime Text is installed, it comes with updated versions of syntax definitions for all of the languages supported out-of-the-box. We constantly are working on fixing bugs on these and improving them at sublimehq/Packages. When the syntax definitions change, the indexing functionality must rescan all source files to index all of the functions, classes and other indexed symbols.

By default (prior to build 3125), one low-priority background process is created per CPU core on your machine to index the files. For projects with a few thousand (or less) source code files, this process is usually done in less than a minute. Larger projects that have tens to hundreds of thousands of files may take longer to scan. Some user’s may experience the fans on their laptop kick on if all cores are actually doing work.

As of build 3125, we are now defaulting to 1 indexer process for single and dual core machines, 2 for quad core, and n-1 for >4 core machines (desktops). You can also choose the number of background processes you want to run via the index_workers setting.

You may also want to check the Console to see if any errors are reported during indexing. It is possible that some source code files may have constructs that the default syntaxes are poor at processing. It may also be that a third-party package has installed a syntax definition that is slow due to extensive uses of regular expressions that cause backtracking.

There is a known issue of an interaction between the JavaScript syntax shipped with build 3124 and the MarkdownEditing package that can cause very slow indexing of Markdown files. See the post below for more details.

Please see the directions at http://www.sublimetext.com/docs/3/revert.html if you wish to disable third-party packages for testing.

In the end, it may just be that you need to let the indexer run for a couple of minutes. Once complete, it will only need to scan files that are changed. It will also allow you to take full advantage of the Definitions popup, which I personally find to be a great aid in exploring and navigating code.

6 Likes

Why is Sublime using significant CPU when idle?
ST3 crashes frequently since Build 3124
Sublime 3124 eat up my CPUs
pinned globally #2
0 Likes

#3

Some users have concerns over indexing all of their NodeJS dependencies. This post discusses how to disable that. Generally, this should not be required, especially with dev build 3125 or beta 3126 and onward.


If you have no interest in being able to jump to the definition of functions in node_modules/, you can use the binary_file_patterns setting to exclude it from indexing and the Goto Anything menu. For example:

"binary_file_patterns": ["node_modules/", "*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
0 Likes

Wildcard ignore in binary_file_patterns
#4

Users of dev builds 3121-3123 and beta 3124 may have experienced performance issues when adding the MarkdownEditing or Jade packages to their install. This post discussed work-arounds. Dev build 3125 and beta 3126 onward require no changes.


Users of the MarkdownEditing project are reporting hangs when opening or indexing Markdown files.

Solutions include:

  • Disable the MarkdownEditing package
  • Install a new version of JavaScript.sublime-syntax into Packages/JavaScript/JavaScript.sublime-syntax.
0 Likes

#5

So would you add "node_modules/*.*" to the index_exclude_patterns attributes within the settings file?

Additionally, once I add that, how can I have Sublime reindex my files (excluding the node_modules/ folder this time during the reindex)?

I found this - https://github.com/SublimeCodeIntel/SublimeCodeIntel/issues/268 - but removing that folder didn’t appear to force a reindex.


EDIT: As @wbond has recently said, node_modules can be excluded by adding "node_modules/" to the binary_file_patterns attribute in your settings file. If you’d like to reindex your files with this new change, navigate to ~/Library/Application Support/Sublime Text 3/Index and delete the contents of that folder. Quit Sublime Text, and relaunch. The application should now start to reindex all files (with node_modules excluded this time).

0 Likes

#6

I’m seeing a CPU spike (for indexing) when I use index_exclude_patterns in my User Settings, but amending node_modules/** to the default binary_file_patterns setting drops the CPU down immediately to near 0.

Am I using index_exclude_patterns wrong or expecting it to do something it doesn’t? Thanks :slight_smile:

0 Likes

#7

Sorry to be dense, but where do I change the index_workers setting? I don’t see a reference to it in Default preferences.

0 Likes

#8

Go to Preferences > Settings and under the Users prefereces set the following line:

    "index_exclude_patterns":
        [
            "node_modules/*.*"
        ]
0 Likes

#9

It is part of the default preferences, near the bottom of the file. Either way, the setting should be placed in the user preferences (right-hand pane) when opening Preferences > Settings.

0 Likes

#10

I’m having the same issue. No matter what I put in the “index_exclude_patterns” setting works. Once set, it just continues indexing and logging errors in the console.

I’ve tried:
“node_modules”
“node_modules/"
“*/node_modules/*”
“node_modules/**”
"node_modules/
."
"node_modules/**.

Thanks for the binary_file_patterns tip, that seemed to stop it from indexing the node_modules folder.

2 Likes

#11

I am in the same boat. It has been indexing for almost forty minutes. Since I am doing node and python, I am using the following:

"index_exclude_patterns":
 [
   "node_modules/*.*",
   "env/*.*"
 ]

Any advice would be welcome. Also, is there a way to see what is being indexed, like a progress tracker or similar, hidden away somewhere?

0 Likes

#12

A percentage of the files indexed is printed in the status bar.

If you have seen indexing for 40 minutes, you likely have the MarkdownEditing package installed. See resolution steps.

As mentioned in the original post, check the Console for any errors that may be occurring.

0 Likes

#13

Thanks! Adding the Javascript folder and JavaScript.sublime-syntax did not work. Disabling MarkdownEditing did work.

I am sorry to keep asking obvious questions, but when you say Console are you referring to macOS Console, or is there a Sublime Text console option? If macOS Console, I did a search for sublime, not much came up. If there is a specific log file path to check out, let me know. Thanks!

0 Likes

#14

It may be that you needed to restart Sublime Text to get the indexers to pick up the new syntax. Or it is possible a spelling or capitalization issue caused the problem.

I’m referring to the Sublime Text Console, which is available on all platforms via View > Show Console.

0 Likes

#15

I’m referring to the Sublime Text Console, which is available on all platforms via View > Show Console.

Found it, thanks! Hopefully others who come to this thread will join me in being just a little less ignorant thanks to your answers. :smiley:

It may be that you needed to restart Sublime Text to get the indexers to pick up the new syntax. Or it is possible a spelling or capitalization issue caused the problem.

Re-tried with JavaScript/JavaScript.sublime-syntax and re-enabled MarkdownEditing. Unfortunately, CPU usage spiked again. Note that I did not have a pre-existing JavaScript folder in ~/Library/Application Support/Sublime Text 3/Packages.

0 Likes

#16

That is correct. Normally users shouldn’t. The process I described is creating an override for a package file, namely JavaScript.sublime-package/JavaScript.sublime-syntax. There is a little more info at http://www.sublimetext.com/docs/3/packages.html.

0 Likes

#17

Makes sense, and that is what I understood to be happening. Thanks for confirming.

MarkdownEditing is not mission-critical by any means, so I can wait for a fix in release.

0 Likes

#18

Just a note, I am looking into index_exclude_patterns right now, and have removed that recommendation for the time being.

0 Likes

#19

It appears that right now index_exclude_patterns only applies to the file name, not the full path. Instead, binary_file_patterns can use used – see the example.

Sorry for initially recommending a solution that didn’t work.

3 Likes

#20

I tried adding my problem directory to the binary_file_patters and now every time i try it open a file in that directory ST hangs. My whole project is basically all javascript, the filetypes are .jade and it tries (and fails) to index every .jade file i have. Currently ST is unusable for me. Is there a strait forward way to rollback to build 3114?

0 Likes