Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS on ARM takes 26 seconds to run an empty file

NodeJS is taking 26 seconds to load on my embedded system.

I have a SOM (system on module) from Microchip. It is an ARM architecture and runs at 500MHz with 128 MB RAM.

It has a BuildRoot image of Linux running on it with NodeJS installed.

I have an empty file named "index.js".

When I run "time node index.js", it takes 26 seconds to complete. If I edit "index.js" to add a "console.log('hello');", it takes 26 seconds before it prints out the message.

So it appears that NodeJS is taking 26 seconds to load and start running the JS file.

I ran "strace node index.js". It is calling mprotect and cacheflush several thousand times for most of the slow down:

13:41:43 cacheflush(0x309228e0, 0x309228ec, 0) = 0
13:41:43 mprotect(0x30902000, 249856, PROT_READ|PROT_EXEC) = 0
13:41:43 mprotect(0x30902000, 249856, PROT_READ|PROT_WRITE) = 0
13:41:43 mprotect(0x30902000, 249856, PROT_READ|PROT_EXEC) = 0
13:41:43 mprotect(0x30902000, 249856, PROT_READ|PROT_WRITE) = 0

This appears to be flushing the instruction and data cache, marking a section of memory as RX, then to RW, then back to RX, then finally back to RW. My guess is that is it copying a function to RAM, modifying it, then running it.

But using "strace -c node index.js" says that this is using about 0.5 seconds. I need to find the other 25.5 seconds.

How do I find the other 25 seconds?

like image 870
Robert Avatar asked Oct 18 '25 06:10

Robert


1 Answers

I found a pre-compiled package at: https://nodejs.org/download/release/latest-v15.x/node-v15.3.0-linux-armv7l.tar.gz

Now it takes 1.6 seconds to execute an empty script.

I can run a script that will print out the compiled configuration of NodeJS to figure out the differences with this: node -e "console.log(process.config);"

Next is to figure out what the differences are and incorporate them into the BuildRoot script.

like image 135
Robert Avatar answered Oct 19 '25 21:10

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!