Atom Helper process takes up 100% CPU
Whenever I execute any of the atom-import-js commands, the CPU goes to 100% and everything in Atom becomes terribly slow.
This happens regardless of whether I run Atom in normal or in dev mode.
Output from top command:
PID COMMAND %CPU TIME #TH #WQ #PORTS MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME
24337 Atom Helper 126.0 02:44.47 22/1 1 158+ 285M- 0B 0B 24325 24325 running *0[2] 0.00000
5174 node 31.9 06:53:28 10/3 0 33 2852K 0B 475M 5170 5173 running *0[1] 0.00000
2346 Google Chrom 6.7 56:04.13 18 1 184+ 287M+ 0B 88M 352 352 sleeping *0[1] 0.00000
Can you share a little on what your project looks like? For large projects, there will be an initial burst as import-js starts indexing all your javascript files. But the burst shouldn't last forever, plus the next time you run it things should be faster (it will reuse the old cache). That being said, you're likely going to get a better experience if you install Watchman as well. See the import-js readme for more on this.
Thanks for a quick response.
The project I first tested it on has 247 JavaScript source files + 102 SCSS files which are also imported. Its node_modules/ dir has 1165 packages.
- Initially I thought the fault is in
node_modules.linux/dir which is use by Docker and has essentially the same 1165 packages. So I deleted it, but performance didn't improve. - Then I tried also deleting the
node_modules/dir itself. That did slightly improve the time it took to run the "Import word" command, but after that the CPU again spun up to 100%. - I waited for a several minutes... then killed it down.
I also tried it on a different project with 940 .js files, 227 .scss files, and 1016 packages in node_modules/.
- And it all worked just fine. Perhaps a small jump in CPU-usage when first running the "Import word" command. But from then on, no performance issues.
So there must be some sort of odd difference between the projects, and it's not the plain number of files.
One difference that might be important is that this first project makes heavy use of named exports (while the second one mostly uses default exports).
I remembered that there were some large compiled .min.js files (around 1MB in size), which weren't listed in .gitignore. I deleted those as well. Initially it seemed that this didn't help... but then the CPU usage dropped down.
I added the problematic directory to excludes config, and the problem went away :)
same problem here from time to time. I try to import something and atom hangs. I have watchman installed on the computer using brew. I have no clue whether importjs actually uses watchman though
I started to experience this problem again too.
I then went back to deleting all these problematic directories and files, and some more... and at one point it started to work again. Added some additional directories to exclude config... we'll see if this prevents the problem from coming back again in the future.
At one point, during messing with this, I even got to the point where the import-js plugin stopped working completely (like the commands weren't even available from the menu). I uninstalled and re-installed it, to get it back to working state again.
But there definitely are some problems in here with this...
I have no clue whether importjs actually uses watchman though
You should see something about this in the import-js logfile: https://github.com/Galooshi/import-js#loglevel
I'd be interested to see more of what's in that logfile. Can you either share here or link to an uploaded gist @macrozone?
@trotzig hi,
This is my .importjs.js file now:
module.exports = {
environments: ['meteor', 'node'],
excludes: ['.meteor/**'],
logLevel: 'debug',
};
but no logfile is created. I restarted atom, but without luck.
ok, i uninstalled importjs and reinstalled. Then i got a message about native modules that were built for an older version of atom and could rebuild it.
after that, it started to work again. also logfile is now there
Interesting. This could definitely be related to building the sqlite3 dependency (I have seen this come up several times in the past).
I'm glad you found a workaround, and I hope this can help others running into the same issue.
Quick question, are you on windows, linux or mac?
mac os x high sierra.
by the way, now the cpu issue is back, but nothing appear in the logfile :-(
Is there anything in the dev console log in Atom?
FYI, I'm also running the latest OSX.
Same here OSX. AFAICT importjs is watching changes in my build directory, which is constantly being recreated. I have public/build in my root project gitignore and build in my public/.gitignore but it doesn't help.
Project structure:
/ (nodejs)
|- .importjs.js (excludes: ['public/**/*'])
|- public (browser)
|- .importjs.js (excludes: ['build/**/*'])
|- build (browser, bundled)
NOTE: I'm also using rollup plugins to transform css and graphql files, so I can
import query from './query.graphql';. Could that be gumming up the works?
@bennypowers If I'm not mistaken, only the project root .importjs.js will be used in your case, so you can probably get rid of the one in the public folder.
I had a look at some of my own projects and their .importjs.js config. I have excludes patterns starting with a dot, e.g.
// .importjs.js
module.exports = {
excludes: ['./build/**'],
}
Could you try changing your excludes config to see if it makes things better?
Seems to have helped, thanks.
Docs show without ., maybe should be updated.
excludes: [
'react-components/**/test/**',
]
Thanks for the callout! I made that change here: https://github.com/Galooshi/import-js/commit/6e88abfe80ffc904363250a95b5ef8afc15b89b5