Concurrent JavaScript — Part IV: Madness!

Abdullah Ali
May 4, 2016 · 2 min read

In a previous article, I talked about I/O performance. Remember when Nexus.js used to convert 400MB of text from UTF-8 to UTF-16LE in 1.8 seconds and I bragged about it?

Image for post

That was quite an achievement for me, but then Christian Landgren pointed out that Node.js easily beat that using cluster.fork(), and it finished in 1.178s.

I was quite distraught, until I split the FileSourceDevice implementation into two types of devices:

First, you have the FilePullDevice, which is the old — but renamed — type.

And then I added the all new FilePushDevice.

FilePushDevice relies on events, it inherits EventEmitter and dispatches the ‘data’ event whenever data is available, so let’s try it out:

Image for post
Image for post

Madness!

It just converted 400MB of data — outputting 800MB! — in 0.484s! That’s almost a quarter of the time it took before!

This performance is the result of piping the streams in parallel, switching from the iconv library to ICU, and good data flow. I also took the time to tune the buffer sizes, which will be programatically adjustable in a later commit. (Don’t forget to remind me, brain!)


I also have another update, I just started implementing networking, starting with UDPSocketDevice. It can’t listen yet, but it works well as a client.

Image for post
Image for post

I’m still pondering the implementation dynamics for binding ports. I’m thinking of implementing an Acceptor class, which will be responsible for accepting connections from a socket.

We’ll see.

If you have any ideas on the matter, I’ll gladly welcome them! I would love to have some input on this subject!


This concludes the fourth instalment in this series. I certainly hope you like how Nexus.js is progressing so far, and as always: you can review the code for the project on GitHub.

You can also follow me on Twitter for real-time progress updates!


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store