- It's all about buffers: zero-copy, mmap and Java NIO - Sep 10, 2016
Full-stack Software Engineer in Bay Area
Github Pages + Hexo (what this site uses)
There are use cases where data need to be read from source to a sink without modification. In code this might look quite simple: for example in Java, you may read data from one
InputStream chunk by chunk into a small buffer (typically 8KB), and feed them into the
OutputStream, or even better, you could create a
PipedInputStream, which is basically just a util that maintains that buffer for you. However, if low latency is crucial to your software, this might be quite expensive from the OS perspective and I shall explain.
Well, here’s what happens when the above code is used:
Then people came up with a great idea of modularizing JS code (probably back in 2003?) the same way you would do for your beloved Java/C++ code libraries. And then there came the CommonJS definition concept by Kevin Dangoor back in 2009. Many people got to know this idea thanks to Node.js, and it works quite well, especially for server side code. Now you can easily use npm and build both the frontend and backend using the same tool very quickly, thanks to the JS community. Since people have the same interface for code modularization, team cooperation becomes much easier and projects gain benefit from much better encapsulation.