-2

I've been hearing that using Express for a Node server will slow down the code. Logically, it makes sense considering Express has 28 dependencies at the root of its dependency tree.

Statistically though, I'm not finding any evidence of this slowing down code. Is the relationship of speed with Express to vanilla Node similar to the relationship of speed with jQuery to vanilla JavaScript? Is there numbers to support or disprove this?

EDIT: Nobody that responded with an answer had an actual answer. If you are curious of the answer, I eventually ran into it. Evidently Express is slower.

Benchmark column graph

If you want to find more details about these tests, refer to this link.

Basically the person created Hello World apps with each technology and calculated how many requests did each of them fill per second.

DougCal
  • 105
  • 1
  • 1
  • 11
  • There was a viral repo on Github (now deleted) where the author posted some vague benchmarks. Ruby on Rails could serve ~200 requests/second @ 1 thread. Node.js could serve 17k requests/second @ 1 thread. Golang with fasthttp could serve 122k requests/second @ 1 thread. Node.js with Express could serve 7k requests/second @ 1 thread. Golang with standard net/http could serve 36k requests/second @ 1 thread. µWS could serve 220k requests/second @ 1 thread. You can read the full thread here - https://gist.github.com/brettdewoody/5ff6aa3334bec46baec5aa4c4f1f1d09 but take it with a grain of salt. – Brett DeWoody Jun 03 '17 at 00:02
  • @BrettDeWoody Thanks, I was looking for an answer like this. – DougCal Jun 03 '17 at 00:10
  • Do a benchmark and see if anything changes with/without Express. – Wolf Jun 02 '17 at 23:52

2 Answers2

2

tl;dr

Probably doesn't matter.


Well, looking at it from a completely practical standpoint, you're going to have a very arduous time building and deploying a server if you're gonna cook it up yourself using "vanilla Node". And at the end of that process, you'll end up having built your own framework, and you yourself will have introduced dependencies. At the end of the day, what you're really asking is, "should I use Express or build my own framework?"

If you're in the business of building your own framework, sure, go for that. If you're looking for a practical way to run a Node.js server, I'd stick with a framework that's already been built, tested, and thoroughly critiqued by the JavaScript community.

Is the relationship of speed with Express to vanilla Node similar to the relationship of speed with jQuery to vanilla JavaScript? Is there numbers to support or disprove this?

That's not really comparing apples to apples. The only comparison that holds valid there, is the idea of using a library/tool/framework or whatever that somebody else (in the business of specifically developing libraries/tools/frameworks) built it and it has been tested, over and over and over again. Sure, maybe you'll get some millisecond differences between using some specific JavaScript function versus using one wrapped in a layer that a library provides (like jQuery's element selection method), but at the end of the day, the cost vs. benefit of this micro-optimization is probably not worth it.

Stick to something you know is going to work, unless you're in the business of purposely developing tools that improve on other existing tools.

Lastly, if you really wanna know, run some benchmarks yourself, using 2 versions of the same "business functionality" (i.e. 2 servers that do the same thing), one written with "vanilla Node" and one using Express. My gut says you'll find very, very minor differences in performances, all else being equal.

Josh Beam
  • 19,292
  • 3
  • 45
  • 68
  • 1
    If the goal is fast development, go with jQuery; if your goal is fast code, go with vanilla JavaScript. Evidently in some cases jQuery is 35x slower than vanilla JavaScript although they are doing the same thing [thread of this discussion](https://stackoverflow.com/questions/4651923/when-to-use-vanilla-javascript-vs-jquery). I wouldn't consider 35x slower micro-optimization in any circumstance. If a library has the potential to slow down code by 35x, it should be a concern if a framework that is used for similar reasons may be doing the same. Without well accepted numbers, we do not know. – DougCal Jun 03 '17 at 01:34
  • 1
    I ran out of space, but by similar reasons I'm implying things like speed of development and readability of code. As I mentioned in the answer with the most upvotes, I can obviously benchmark this, but it won't become a widely accepted truth. Something like how Google proved C++ is faster than Java, Scala, and Go [the report](https://days2011.scala-lang.org/sites/days2011/files/ws3-1-Hundt.pdf) is the type of answer I'm looking for. Knowing this can help in a lot of decisions as to whether use Express of Node in production. – DougCal Jun 03 '17 at 01:42
0

Do tires make a car slower? Logically it makes sense given the friction between the tires and the road. Some tires even advertise increased friction. If I want speed and efficiency, why would I want that! Obviously the best tire provides the least friction.

Of course, a car without tires wouldn't be all that useful would it? And, in some cases, we might actually choose tires with better friction. While folks in California aren't going to need snow tires, folks in Chicago certainly will.

Your question is nonsensical. You're basically asking what's better between two methods which are used for different things. If you don't need the framework that Express provides, obviously do not use it. If you do... probably best to adopt the framework that's already well-tested, but for stability and performance.

This is about choosing the right tool for the job.

Brad
  • 159,648
  • 54
  • 349
  • 530