Why did the college want us to study Compiler Construction?

Arpit Bhayani

Arpit Bhayani

Nov 18, 2022 • 2 min read


Why did the college want us to study Compiler Construction? Do we really need it in our regular work? 🤔

Here’s how I used a compiler optimization technique to implement a key feature in Dice DB.

Compilers optimize string allocations by not allocating the same string again. Instead, it just reuses its reference. This optimization is called String Interning and Python uses it to make its runtime faster.

âš¡ But, how did I use this in a database?

Dice DB is an in-memory KV store, in which I am implementing key references similar to Foreign Key in relational databases.

This is a classic place where storing the same key again would have led to severe memory consumption.

âš¡ String Interning gives a huge performance boost to a KV store because storage engines do not really need that actual Key once the referred value (object) is de-referenced.

This insight made it feasible to adopt String Interning and implement key references with ease.

Because of a comprehensive test suite, it was easy to ensuring none of the existing functionalities break. Unit and Integration tests for the win.

âš¡ In case you are interested in understanding String Interning, check out my 30-min video explaining it in depth and giving a walk-through of CPython implementation.

https://lnkd.in/gCaHWuF3

âš¡ Learning never goes in vain.

CS Engineering is a wonderful domain. Do not limit yourself to just work-related stuff or worse interview-related stuff.

I started building while I was going through Redis Internals, and I do have a course on it

arpitbhayani.me/redis

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses