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?