Node.js require becomes extremely slow after OS X has been running for a while

When I reboot my Mac, starting up Node.js apps is nice and fast. Later, after the Mac has been on for a few hours, it gets REALLY slow.

I've used process.hrtime() to time various things, and it seems that it's all the require calls that take time, ie loading dependencies. Once everything is loaded, my apps run reasonably fast.

The difference is extreme: just after I've rebooted, an app may take 300ms to get through the require calls, then it takes something like 30 seconds once it's been on for a few hours.

What could be causing this?

Since how fast executing require is perfectly related to a disk loading performance. So I suppose It's highly possible that HDD/SSD or whatever your project belongs causing that. it's working fine right after you rebooted so maybe some background software(such as virus scan or auto downloader) is making IO blocking

You'd better start by checking your CPU/RAM/HDD status while the issue is occurring and see what happens if you move your project into USB flash drive or external HDD