Rob Meijeren
Jun 24 ● 3 min read
Let's talk performance! Node server VS Dart server.
For this blogpost I wanted to talk about the performance of a node server VS a Dart server. I've been working on a personal flutter application project which talks to a server. I built the API in node/express as we do at SpringTree, It's what I was familiar and comfortable with. But, then I started to think.. well I can also write the API in Dart just like the flutter application so that I have a unified set of typings and I don’t have to, as I have been doing till now, convert my TypeScript types to Dart types with the parsing to/from json for it that needs to be written.
The main thing I was worried about was performance. How would a Dart server compare to the node server I have running. The only real way to answer this question would be to rewrite what I had in Dart. But to write the entire thing to Dart and then find out if it performs shitty ain’t the best use of my time. So I figured… let’s just write a small thing in Dart and see how that compares.
One thing that I thought would use the most resources is the fetching of electric vehicle charging locations. I had just under 8000 locations in my database and thus it would be a good candidate to see how the Dart server would handle large datasets that needed to be retrieved.
During the rewrite I figured out that Dart does have some quirks especially when it comes to getting the data from a database. Luckily for a project I work on at SpringTree I already dabbled a bit with databases and queries. altough that was with SQLite and this would be with PostgreSQL, SQL stays SQL and thus the basic structures I could borrow from that project.
For the rest it was quite straightforward. By using the shelf package the routing and getting the server started was a breeze and the comparison could begin and it would give a different result then I expected.
When getting a subset of locations (in this case it would be around 60 locations that we retrieve) the response times didn’t differentiate all that much.
Fig 1. limited subset with node
Fig 2. limited subset with Dart
It did fluctuate with both a bit but generally it is about the same response time. But the interesting part would come when we would retrieve all locations.
Fig 3. all locations with node
Fig 4. all locations with Dart
Although also here there are fluctuations in the response times the difference above was about the average difference between the 2 servers. Personally I would have expected Dart to have been quicker. Mostly because Dart is statically typed and thus it know what it retrieves and doesn’t need to do a lot of checks to make sure some variables contains what it says it does.
A single longer response time could have been accounted for by the fact that I was using a remote database and that getting the data would take a bit longer but since it was consistently slower that can be ruled out to be the whole cause.
Still the response time isn’t crazy long. Especially when you figure that getting just under 8000 rows isn’t something you do everyday. So I probably still will rewrite my API in Dart as it will be way easier with the typings. Also all the typings are already written as I needed to for the flutter application so it is mainly getting the routes working in Dart. That can become interesting as it also will involve pdf creations and I have no clue how to do that yet in Dart but I will probably figure it out and I will learn something from that which I might be able to apply in my work at SpringTree.
If you want to try it out yourself… you can. I made a repo for this little project in my github account. check it out and let me know if you see something you would do differently…
https://github.com/Rob-Meijeren/node-vs-dart-server-comparison