Compilation times and idiomatic D code

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 13 12:23:11 PDT 2017


On Wed, Jul 05, 2017 at 09:45:55PM -0600, Jonathan M Davis via Digitalmars-d wrote:
[...]
> In this case, I think that it's more that Voldemort types are biting
> us than that ranges are biting us (though the Voldemort types are
> typically ranges, so in practice, using ranges ends up biting you).
> 
> https://issues.dlang.org/show_bug.cgi?id=15831
> 
> I think that there's a good argument that Voldemort types aren't
> actually a particularly good idea given these issues, but the work
> that's being done to compress symbols should at least reduce the
> problem.
[...]

Here's the latest update on this bit of drama:

Today, I decided to sit down and refactor my code.  I've heard tell that
Voldemort types tend to cause an explosion in symbol size, and today I
thought it'd be interesting to see just how big of a difference this
actually makes.

I could not believe my eyes.

Before the refactoring, my executable sizes (I have 2 executables in
this codebase) were 37.3MB and 60.0MB, respectively.

After the refactoring, my executable sizes were, respectively, 8.2MB and
10.2MB. That's a 5x and 6x reduction in executable size, respectively.
Whoa.

And all I did was to move Voldemort structs out into module-level
private structs. I.e., this:

	auto myFunc(Args...)(Args args) {
		static struct Result {
			...
		}
		return Result(args);
	}

became this:

	private MyFuncImpl(Args...)
	{
		...
	}

	auto myFunc(Args...)(Args args) {
		return MyFuncImpl!Args(args);
	}

And you get an instant 5x to 6x reduction in executable size.

Now mind you, the ridiculous symbol size problem still exists; the
executable still contains some huge symbols.  The difference is that now
the longest symbol is "only" 86KB, whereas before the refactoring, the
longest symbol was 777KB (!).  So the problem is less severe, but still
present.  So symbol compression is still a very important part of the
eventual solution.


T

-- 
Windows: the ultimate triumph of marketing over technology. -- Adrian von Bidder


More information about the Digitalmars-d mailing list