October 25th, 2023
heart3 reactions

Deep Dive Analysis: Why did this dll increase in file size by 50%?

We recently noticed that one of the dlls that we produce had suddenly jumped up in file size. The WinUI Controls library, Microsoft.UI.Xaml.Controls.dll that ships as part of Windows App SDK had ballooned in size in our internal builds. It had suddenly grown from 7 MB to 10.5 MB – approximately a 50% increase in size. What had happened to cause this? We needed to investigate the issue and fix it.

This post is a deep dive into the analysis that was done to figure out what caused this sudden increase in file size and how it could be fixed.

File size of a dll is important not just due to its impact on diskspace on a user’s machine but it also has an impact on the app at runtime due to the number of pages loaded into memory. We have internal automated processes to check the size of each dll that is built and to flag up instances where there is a substantial increase in size. That’s what brought this issue to our attention. We needed to investigate to figure out what caused the increase and how to fix it.

The first thing to do was to look over the commits that had gone into the branch within the relevant time period. None of the code changes that went in looked like they could have had such an impact. It is reasonable to expect new code and new features to increase the file size of the built binary, but the magnitude of the increase was not reasonable based on what had changed. The only change that stood out as a potential candidate was an update to the version number of the C++ compiler build tools that we use. We updated MSVC tools from 14.35 to 14.36. Since none of the other changes looked like they could have had such a big impact, this change looked like the most likely one to have introduced the file size increase.

I tried building the dll on my machine, switching between the two MSVC versions and was able to confirm that moving from 14.35 to 14.36 did in fact increase the file size by 50%. But how?

When investigating issues related to file size of a dll, a great tool to use is SizeBench (see blog post SizeBench: a new tool for analyzing Windows binary size). It is available to install from the Microsoft Store. This is a powerful tool that lets you open a dll along with its matching pdb symbols file and see a breakdown of how the space is being consumed by the different parts of your dll. One very useful feature is its ability to perform a diff of two different versions of a binary to see what has changed. If a particular class or function has suddenly gotten much bigger, it will show up in the diff.

We look at a diff of the Compilands (Obj files) and sort by file size diff.

A screenshot of SizeBench showing the diff in file size of a list of obj files

No one .obj jumps out as the source of the 3.5 MB file size increase – instead it seems like many of the compilands increased by a few dozen kilobytes. We drill in some more to one of the obj files to see if we can figure out what is going on.

Here we see a breakdown of the 87 KB increase in ScrollPresenter.properties: