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.
âš¡ 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