I started YouTube channel in 2020 during COVID-19 pandemics. It was perfect timing for me to finally align my thoughts. After years of thinking, I just started recording and publishing videos. My friends and colleagues asked me for years to record my talks and publish it for others to see. All opinions and advices are my own, and take them with grain of salt, I am just a regular guy doing interesting things online.
I cover broad topics from computer science and engineering. Including BSD, Linux, data structures, algorithms, machine learning, programming languages design and implementation, etc. Please check my YouTube channel and subscribe if you like topics that I cover. Feel free to leave comments and suggestions.
I am also active on Twitter, so you can get in touch with me over there as well.
I will start here series about language virtual machines. I will first show native examples in C and in few other dynamic languages such as Python, Ruby and Lua. Their speeds will be compared.
After we have insight into what kind of speeds we expect from which programming language implementation, we will try to explore approaches in VM design and implementation.
Our main goal is to show speed of the simplest but functional possible VM’s and some basic optimizations.
VM’s will be written in C, C99 and in some cases C11 standard.
System (my home desktop computer) on which benchmarks will be run is following:
In this post, I will show simple loop, its alternative implementation with imaginary JIT compiler that “optimizes” its internals. I will also show speed benchmark.
Loops are core building blocks in every program. In Python, they iterate over sequence. However in C, they keep looping while some condition is meet.
Take for example:
Tracing JIT would recognize loop and try to optimize it. If code above is in C, there is really no need to do such a thing. However, if your code is in Python, JIT will dramatically improve speed over loops which “captured” variables stay with same type.
Anyway, we will keep C example, and try to work on it. Code above would be JIT compiled to look like following:
compiler loop1 loop2 gcc 0.293s 0.261s clang 0.284s 0.284s
I’ve decided to start writing about things that I think about daily. For almost 10 years, I’ve been thinking about successfully implementing VM for Lua or Python.
Lua has more educational purpose in my life. I have learned a lot from its simple implementation.
Python is language of choice for me. I like its elegance and simplicity, but I hate its internal ecosystem. It is huge. I wish we could install
remodules using pip instead of they coming included inside python implementations.
This blog will be mainly about implementing Virtual Machines. Practices might not be the best, but idea is to implement cool stuff, so other can learn from it.
I will text with intermediate level of knowledge. I expect that you understand compilation, basic VM principles, JIT compilation, etc.