The AMD Ryzen 9 5950x is a beast of a CPU with 16 cores and 32 threads. I have been running a bunch of benchmarks around one million lines of code but I wanted to really push the 5950x and Delphi to their limits so I created a group of projects in Delphi which combined have over one billion lines of code. Each project has a unit which contains 4 million lines of code and there are 250 projects. I loaded the projects up into Delphi Parallel Build which uses the parallel programming library in Delphi and away we go.
Just how much is 1 billion lines of code anyway? There is a nice millions of lines of code visualization which shows the sizes of various code bases with things like CryEngine 2 being 1 million lines of code, Intuit Quickbooks being 10 million lines of code, and Google’s code repository having 2 billion lines of code.
In order to create the project with one billion lines of code I started out with a utility app I built in Delphi that takes in 3 sections of text. The top section of a unit, the code I wanted to duplicate X times, and the button section of a unit. Next I found a nice piece of Object Pascal code (from here) which is the LU_factor function from the Scimark benchmark. I calculated how many lines the function was and how many lines of code I wanted to create and ran a loop to create the number of desired lines. I tested a number of different file sizes including 1 million lines, 2 million lines, 4 million lines, 8 million lines, and 32 million lines. The 1, 2, and 4 million line units all open in the Delphi IDE pretty well. The 8 million line unit runs out of memory during the load. The 32 million line unit ran out of memory before the load and therefor only loads an empty editor window. I also tested opening the 4 million line unit in Visual Studio Code and Visual Studio just to see how each of the 3 editors would perform. Suffice to say they were all able to edit the file with a little slowdown in different places when interacting with the file.
I also took this project and committed it to GitHub (https://github.com/FMXExpress/One-Billion-Lines-Of-Object-Pascal-Code) as I wanted to see if the GitHub pipeline could handle one billion lines of code. Suffice to say the GitHub desktop app and site worked flawlessly with the one billion lines of code project. The first screenshot here is during the commit of one billion lines of code to GitHub.
The next screenshot here is during the start of the compile of the one billion lines of code. You can see each of the 32 threads fire up on the 16 core Ryzen 9 5950x CPU. In order to monitor the CPU and Disk IO usage of Delphi’s parallel compile I used Task Manager DeLuxe or TMX (which is also built in Delphi). Task Manager DeLuxe is pretty amazing in the amount of information it provides regarding your Windows system. TMX features a dark (very 2020) and light mode. TMX is available from MiTeC which also makes a wide variety of Delphi components that give you access to a lot of the same information found in TMX. Most of the information in TMX is probably available for you to use in your app with the MiTeC System Information Component Suite.
During this parallel build I am also using the Ryzen Master overclocking app from AMD to see some additional statistics about the temperature and other metrics of the AMD Ryzen 9 5950x. For this blog post I have it set to Precision Boost Overdrive in the Creator Mode profile. In the previous three blog posts (750k lines of generic Object Pascal in 12 seconds, 300 Windows apps in 45 seconds, and 1 million lines of C++ in ~2 minutes) about the AMD Ryzen 9 5950x I was running the stock clock speed and profile.
The AMD Ryzen 9 5950x runs on the Zen 3 architecture. Here is a video from the announcement of the architecture earlier in 2020.
According to Wikipedia, “Zen 3 is a significant incremental improvement over its predecessors, with an IPC increase of 19%, and being capable of reaching higher clock speeds.
Like Zen 2, Zen 3 is composed of up to 2 core complex dies (CCD) along with a separate IO die containing the I/O components. A Zen 3 CCD is composed of a single core complex (CCX) containing 8 CPU cores and 32 MB of shared L3 cache, this is in contrast to Zen 2 where each CCD is composed of 2 CCX, each containing 4 cores each as well as 16 MB of L3 cache. The new configuration allows all 8 cores of the CCX to directly communicate with each other and the L3 Cache instead of having to use the IO die through the Infinity Fabric.
Zen 3 also features Smart Access Memory (SAM), a technology allowing Zen 3 processors to directly access all of a compatible graphic card’s VRAM, allowing an increased FPS of up to 11% in certain games. SAM is an implementation of resizable BAR, an optional feature introduced in PCIe 2.0 that, as of the launch of Zen 3, only AMD has explored. As of December 2020, Intel and Nvidia are reportedly working on implementing Resizable BAR in the near future.”
Here is a screenshot from the Disk I/O tab during the one billion lines of object pascal compile in Delphi.
In the next screenshot here we have the full desktop during the compile including Delphi in the background with the Delphi Parallel Build running, TMX tracking the statistics, and the Ryzen Master app in the foreground showing the temperature and other stats.
The other screenshots from TMX show the 32 threads in use. The next screenshot shows the single view of the CPU usage. The full specs on the AMD Ryzen 9 5950x benchmark machine are AMD Ryzen 9 5950x, 64GB DDR4 3200MHz RAM, 1TB NVMe SSD + 2TB HDD, NVIDIA GeForce RTX 3070 8GB, and Windows 10 Pro.
The third tab on the Performance tab in TMX is the Advanced tab. It shows C1, C2, and C3 in addition to the DPC, Interrupt, and Privileged graphs for the AMD Ryzen 9 5950x on Windows 10 Pro.
In the next screenshot we can see that the one billion line Delphi object pascal compile is almost complete. I switched the Ryzen Master app to Basic Mode for this screenshot so you can see the basic information it shows verses the Advanced information in the previous screenshots.
The final TMX screenshot here shows that the one billion lines of object pascal has just completed so you can see the full CPU graph of each of the 32 threads on the 16 core CPU. There is a nice memory graph below the CPU thread usage view as well showing the 64GB total of the machine.
Finally we have a screenshot of the completed build in Delphi Parallel Build showing that it took 335676 milliseconds to compile one billion lines of Object Pascal code in 250 projects using MSBuild on a 5950x. You can also find out more about the MSBuild command line options in relation to Delphi in the Embarcadero DocWiki.
MSBuild <projectname> [/t:<target name>][/p:config=<configuration_name>][target:Deploy][/p:platform=<platform_node_name>]
Suffice to say that compiling 1 billion lines of code isn’t in and of itself a significant thing. However, in comparison to older hardware being able to do this in around 5 minutes is pretty amazing. Additionally, compared to some other compiled languages compiling 1 billion lines of code with Delphi in around 5 minutes is FAST. The other article I did featured the 1 million lines of C++ in around 2 minutes can be extrapolated to 2000 minutes (or 33.33 hours) to compile 1 billion lines of code in C++ with 16 cores. This does not tell the full story as the C++ project was more complex with it’s 128 forms but it does give a general idea on some speed differences between the compilers. The 1 billion lines of Object Pascal are also not complex code. We can go back to the first article I did with the AMD Ryzen 9 5950x and see that it took 12 seconds to compile around ~750,000 lines of complex code using generics. Extrapolated out that would be 1 million lines of complex code in 16 seconds and 1 billion lines of complex code in 266 minutes or 4.4 hours.
This was a lot of fun to put this one billion lines of code project together if not entirely scientific. Different workloads and different codebases are going to provide different results. If you’ve never used Delphi before or even if you have you can check out LearnDelphi.org to find out more tips and tricks about using Delphi (like allocating 32GB of memory in your app). Delphi uses a single pass compiler which is one of the reasons for the fast compile speed. You can find out more about one pass compilers on Wikipedia. You can find out more about the Delphi compiler itself over in the Embarcadero DocWiki. You can also find out more about multi-pass compilers on Wikipedia.