Moment.js instantiation slowness

Was doing some test speedup/performance improvement work recently on the search API and found out something; the moment.js library takes around 100 microseconds (or .1 milliseconds) to create a new instance.

Why is 100 microseconds a big deal?

If you're processing:

  • 100 records
  • Where each record has 7 date fields
  • Then you've created 70,000 microseconds of work
  • Or 70 milliseconds of processing delay.

By doing some memoization of date formatting in our API, we've seen these performance improvements:

Response Times


Without making any significant changes, we've managed to shave 41ms off of our response time on average!

Hope this helps someone else.

Performance Improvement via node 4 to node 6

My team at work recently upgraded our codebase to use to node 6.9, as node 6 has recently gone to LTS.

In the picture below, the 1st line is the upgrade from node 4 to node 6, and the corresponding flattening of memory usage vs. load.

The 2nd line is our removal of redis connection queueing in the application.

All of all, the memory consumption of our application is now averaging around 150MB, down from a high of 1GB!

Hope this information helps all those teams considering upgrading their node projects.

Memory usage graph showing decreasing memory usage

Superagent/Request Memory Leaks

Superagent/Request Memory Leaks

The last several weeks Thomas Hunter and myself have spent some of our nights and weekends trying to track down memory leaks in an API we both work on.

We were seeing a distinct pattern, that when the API was put under a certain amount of load, that we would start slowly bleeding memory.

We've found three results:

  • Superagent, when put under a certain threshold of load and then connections timeout, can leak memory.

  • Request, when put under a certain threshold of load and then connections timeout, can leak memory.

  • Superagent, when not explicitly assigned a timeout parameter, can hold connections open and therefore leak memory

    • The fix for this is to call req.timeout(YOUR_TIMEOUT_VALUE) to resolve.

The fixes for these issues are all in the latest versions of the libraries