<p dir="auto">Couldn't find a previous issue on this, so I'd like to open a tracking issue for this. We've known this for a long time, but the metadata format for the compiler is <em>far</em> too large and there are surely methods to shrink its size and impact. Today when I compile <code class="notranslate">librustc</code>, I get the following numbers:</p>
<ul dir="auto">
<li><code class="notranslate">librustc.rlib</code> - 64MB
<ul dir="auto">
<li><code class="notranslate">rustc.o</code> - 12MB</li>
<li><code class="notranslate">rust.metadata.bin</code> - 32MB</li>
<li><code class="notranslate">rustc.0.bytecode.deflate</code> - 21MB</li>
</ul>
</li>
</ul>
<p dir="auto">This means that the metadata is <strong>three times as large</strong> as the code we're generating. Another statistic is that <strong>36% of the binary data of the nightly</strong> is metadata.</p>
<p dir="auto">There are, however, a number of competing concerns around metadata:</p>
<ul dir="auto">
<li>Reading metadata needs to be <em>fast</em>. Rustc reads a lot of metadata for upstream crates, and it needs to quickly be able to read the minimum set of metadata for crates. This is currently achieved by storing metadata <em>uncompressed</em> in rlibs to allow LLVM to mmap it directly into the address space and page it in for reading.</li>
<li>Metadata needs to be fairly free-form to allow encoding various types of data into it. Ideally it's also extensible into the future so at some point we can use newer compilers against older libraries (this currently not possible for other reasons).</li>
<li>All libraries need metadata available in them (currently). This means that if a library produces a dylib/rlib pair (the stdlib is one of the few that does this) then the metadata is duplicated among artifacts. It also means that metadata must be suitable to place inside of a dynamic library.</li>
</ul>
<p dir="auto">There are a few open issues on this already, but none of them are necessarily a silver bullet. Here's a smattering of wishlist ideas or various strategies.</p>
<ul dir="auto">
<li>Changing metadata formats may gain us a win. Currently we're using a "variant" of EBML. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="19720150" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/9303" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/9303/hovercard" href="https://github.com/rust-lang/rust/issues/9303">#9303</a></li>
<li>Move metadata to a separate crate for faster iteration, allowing external tools to inspect, or in general improving the overall quality of the code. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="4123084" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/2213" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/2213/hovercard" href="https://github.com/rust-lang/rust/issues/2213">#2213</a></li>
<li>Being able to actually inspect metadata would probably give a helpful hand into what can be eliminated. <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="4377168" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/2326" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/2326/hovercard" href="https://github.com/rust-lang/rust/issues/2326">#2326</a></li>
</ul>
<p dir="auto">More will likely be added to this over time as it's a metabug.</p>
<p dir="auto">trans codegen feeds the zeroed discriminant back into match in a loop</p>
<p dir="auto">Some examples, courtesy of <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/eddyb/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/eddyb">@eddyb</a> and <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dotdash/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dotdash">@dotdash</a></p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fn main() {
    let mut result = Box::new(42);
    let mut i = 0;
    loop {
        match result {
            x =&gt; {
                println!(&quot;A&gt;&gt;&gt; {:p}&quot;, &amp;*x);
                println!(&quot;A: {:?}&quot;, x);
                result = Box::new(42);
                if i &gt; 10 { break; }
                i += 1;
            }
        }
    }
}"><pre class="notranslate"><span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> result = <span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">42</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> i = <span class="pl-c1">0</span><span class="pl-kos">;</span>
    <span class="pl-k">loop</span> <span class="pl-kos">{</span>
        <span class="pl-k">match</span> result <span class="pl-kos">{</span>
            x =&gt; <span class="pl-kos">{</span>
                <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"A&gt;&gt;&gt; {:p}"</span>, &amp;*x<span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"A: {:?}"</span>, x<span class="pl-kos">)</span><span class="pl-kos">;</span>
                result = <span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">42</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-k">if</span> i &gt; <span class="pl-c1">10</span> <span class="pl-kos">{</span> <span class="pl-k">break</span><span class="pl-kos">;</span> <span class="pl-kos">}</span>
                i += <span class="pl-c1">1</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><a href="http://is.gd/6Xj4a4" rel="nofollow">playpen</a> here yields:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="A&gt;&gt;&gt; 0x7fedb4423008
A: 42
A&gt;&gt;&gt; 0x0
playpen: application terminated abnormally with signal 4 (Illegal instruction)"><pre class="notranslate"><span class="pl-v">A</span>&gt;&gt;&gt; <span class="pl-c1">0x7fedb4423008</span>
<span class="pl-v">A</span><span class="pl-kos">:</span> <span class="pl-c1">42</span>
<span class="pl-v">A</span>&gt;&gt;&gt; <span class="pl-c1">0x0</span>
playpen<span class="pl-kos">:</span> application terminated abnormally with signal <span class="pl-c1">4</span> <span class="pl-kos">(</span><span class="pl-v">Illegal</span> instruction<span class="pl-kos">)</span></pre></div>
<p dir="auto">Another one, courtesy of <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/eddyb/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/eddyb">@eddyb</a>:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fn main() {
    let mut result = (Box::new(12), 34);

    // Run in a loop to demonstrate the zeroing:
    let mut i = 0;
    while i &lt; 4 {
        match result {
            x =&gt; {
                println!(&quot;{:p} {}&quot;, &amp;*x.0, x.1);
                result = (Box::new(12), 34);
                i += 1;
            }
        }
    }
}"><pre class="notranslate"><span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> result = <span class="pl-kos">(</span><span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">12</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">34</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c">// Run in a loop to demonstrate the zeroing:</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> i = <span class="pl-c1">0</span><span class="pl-kos">;</span>
    <span class="pl-k">while</span> i &lt; <span class="pl-c1">4</span> <span class="pl-kos">{</span>
        <span class="pl-k">match</span> result <span class="pl-kos">{</span>
            x =&gt; <span class="pl-kos">{</span>
                <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{:p} {}"</span>, &amp;*x.<span class="pl-c1">0</span>, x.<span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                result = <span class="pl-kos">(</span><span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">12</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">34</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                i += <span class="pl-c1">1</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><a href="http://is.gd/ntbj0j" rel="nofollow">playpen</a> yields:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="0x7f05c5823008 34
0x0 0
0x0 0
0x0 0"><pre class="notranslate"><code class="notranslate">0x7f05c5823008 34
0x0 0
0x0 0
0x0 0
</code></pre></div>