lp0 on fire

My personal blog

Website: Optimizing generation

After pondering at work, I decided to put more effort into optimizing the website generation. I had two goals in mind: replacing jsdom and improving writeFile's performance.

JS-DOM

"Dom" in Dutch means "dumb", so reading DOM always makes me chuckle a little.

While jsdom is a very accurate emulation of the browser's DOM, I needed speed and not accuracy. cheerio wasn't complete enough for my use-case and I didn't know any other library at the time of writing the initial generator.

Now that I spend some time researching, I found linkedom, an (almost) drop-in replacement for jsdom without the accuracy but with almost amazing speed and a very low footprint. It made me realize how much jsdom was actually bottlenecking my generator. With this change alone it became blazing fast, but there was still room left for improvement.

Async

On the low-end desktop I use at work I noticed the performance impact of having slow I/O operations. In this regard my program could improve easily by making it async. I don't manipulate the produced file, so I could write everything in parallel.

...and so I did!

While the results don't matter much on high-end hardware like my personal desktop computer, it does wonders for low-end hardware like my office pc or a low-end vps running the build command for each commit.

Result

A massive decrease in complexity and a massive increase in performance.

Build time:

  • old: 14s
  • new: 5s

Packages:

  • old: 79
  • new: 38