r/Compilers • • Sep 21 '26

Struggling to understand V8's large codebase. Help?

Hello,

I have been trying to understand the inner-workings of Chromium's V8 engine for a research project. So far, I have gone over the parser with the help of ECMAScript. Currently, I am working through the AST and scoping part. It is a slow process and the codebase is massive, but resources are also sparse. I have only found various blogs and articles online and though they are great, none of them can contain the extreme volume of information and intricacies of the source.

I still think the most effective method is reading the source code, but the scale is quite overwhelming.

I have considered tracing execution using gdb, but due to my limited experience with it, I haven't able to take that step yet. I am not sure how I would even make use of gdb here.

Has anyone studied this codebase, or even a similarly large one for compilers, in the past? Any tips on how to systematically deconstruct the implementation?

31 Upvotes

15 comments sorted by

View all comments

Show parent comment

2

u/ccapitalK Sep 23 '26

Sure, it wasn't anything too special. I needed to root cause some complicated memory leaks, devtools wasn't cutting it, so I wrote an offline script that could parse the v8 heapsnapshot format (as serialized by devtools when you click save), and then do some basic graph traversal algorithms. Once I had that working I wrote some code to do some grouping and heuristics on top of this representation to find patterns that lead me to the leaks (and also some memory optimization opportunities as well, understanding SMIs + the v8 object model helped tremendously for reasoning about memory use on the JS heap).

The main thing that got me started was looking at the heapsnapshot in disk, realizing it was json, then grepping for the key names in v8. Once I found the string literal in the c++ code (I think it was in src/profiler), I then read the surrounding code, and with some experiments on a few snapshots I had already taken, I had a parser up and then a simple set of graph cursor datatypes over the raw uint32 node/edge arrays. I was mostly building this to solve a problem so I didn't put much effort into designing the system upfront, I just experimented and built useful abstractions as I found them, it was exploratory coding so planning wouldn't have made much sense anyway.