High CPU load in combination with serialport


When I use serialport in combination with Electron, the CPU goes through the roof (130% on a recent MPB). The same code running on the same iojs version but seperately only uses a very small percentage (about 7%). The code does nothing but connect and read data coming from the port. I know the CPU load is not caused by things like logging or using the Electron IPC bus because I’ve cut out all overhead like that. Any idea what might cause something like this?


Have you tried using the Developer Tools to profile the CPU usage?


I am running the serial code from the main.js file, so it is not part of an application window.


That does make things significantly harder to debug. This is why as much Atom code as possible is done from the renderer process. I understand there are ways to debug stuff outside the renderer process, but from what I understand it is at a C level, not a JavaScript level.


I’ve moved the serialport code to the main window, but the devtools don’t seem to tell me much. A recorded CPU profile just gives me “100% program” “0%idle”, and a timeline recording tells me nothing.

I guess I’m a bit screwed with this :frowning: I don’t have the knowledge to debug the C code.

I did another standalone test where I required the same module running the serial code from my project, but from a standalone script with a system installed iojs-v2.3.1. Now when this code/module requires the native ‘serialport’ module does it use the same binary as was compiled against the electron v8 headers when I ran electron-rebuild?

The code again runs fine without Electron.


For now I have worked around it by putting the serialport code in a seperate “deamon” process and running it alongside my app streaming the data through a localhost socket. This is of course far from ideal, but at least the cpu stays ok. The deamon only uses about 3% cpu. That’s 127% less :wink:

I was forced to do this because apart from high cpu usage, the data input also became instable after a little while, making the serialport completely useless.

I will create an issue on the electron github. Hopefully someone can look into it someday.


Have you created one?


No eventually I didn’t. I ran out of time and I gave up on the project when next I encountered that the UI I was drawing was also draining the cpu heavily. I will try pick up where I left soon and see if the new version of electron / node makes any difference. Then try to isolate the problems better and report an issue.


Done another test with Node 4.1.1. The behavior is still the same, so I’ve created an issue for it now.