Skip to content

Add benchmark allocation support and improve Emit table size#29411

Merged
agocke merged 1 commit intodotnet:masterfrom
agocke:fix-nummethods-heuristic
Aug 30, 2018
Merged

Add benchmark allocation support and improve Emit table size#29411
agocke merged 1 commit intodotnet:masterfrom
agocke:fix-nummethods-heuristic

Conversation

@agocke
Copy link
Copy Markdown
Member

@agocke agocke commented Aug 21, 2018

After I added support for measuring allocations in the compiler
benchmark suite I noticed in a PerfView trace that we were often
resizing the arrays we used for the Emit tables. Looking more closely at
how we allocate the tables, I found that we were using an approximation
that was very close to the actual size of the tables needed, but
systemically undercounted. Ironically, this may be worse than being
farther off since it meant that we were getting right to the edge of
available space, before requiring a resize, meaning a new large
allocation, and copies from all of the entries in the old tables to the
new tables.

By applying a multiplier to the table size and allocating more memory
for the tables, I've actually decreased the total amount of memory
allocated during emit.

Before:

BenchmarkDotNet=v0.11.0, OS=Windows 10.0.17134.228 (1803/April2018Update/Redstone4)
AMD Ryzen 7 1800X Eight-Core Processor (Max: 3.60GHz), 1 CPU, 16 logical and 8 physical cores
Frequency=3509032 Hz, Resolution=284.9789 ns, Timer=TSC
.NET Core SDK=2.1.300-rtm-008866
  [Host]     : .NET Core 2.0.9 (CoreCLR 4.6.26614.01, CoreFX 4.6.26614.01), 64bit RyuJIT
  Job-ZXPACQ : .NET Core 2.0.9 (CoreCLR 4.6.26614.01, CoreFX 4.6.26614.01), 64bit RyuJIT

Toolchain=FixedCsProjToolchain

  Method |     Selection |     Mean |     Error |   StdDev |      Gen 0 |      Gen 1 | Allocated |
-------- |-------------- |---------:|----------:|---------:|-----------:|-----------:|----------:|
 RunEmit |      FullEmit | 823.4 ms | 16.046 ms | 21.96 ms | 43000.0000 | 10000.0000 |  40.68 MB |
 RunEmit | SerializeOnly | 210.0 ms |  5.215 ms | 15.38 ms |  2000.0000 |  1000.0000 |  18.23 MB |

After:

BenchmarkDotNet=v0.11.0, OS=Windows 10.0.17134.228 (1803/April2018Update/Redstone4)
AMD Ryzen 7 1800X Eight-Core Processor (Max: 3.60GHz), 1 CPU, 16 logical and 8 physical cores
Frequency=3509032 Hz, Resolution=284.9789 ns, Timer=TSC
.NET Core SDK=2.1.300-rtm-008866
  [Host]     : .NET Core 2.0.9 (CoreCLR 4.6.26614.01, CoreFX 4.6.26614.01), 64bit RyuJIT
  Job-IELZBC : .NET Core 2.0.9 (CoreCLR 4.6.26614.01, CoreFX 4.6.26614.01), 64bit RyuJIT

Toolchain=FixedCsProjToolchain

  Method |     Selection |     Mean |     Error |    StdDev |      Gen 0 |     Gen 1 | Allocated |
-------- |-------------- |---------:|----------:|----------:|-----------:|----------:|----------:|
 RunEmit |      FullEmit | 852.0 ms | 16.915 ms | 38.864 ms | 43000.0000 | 9000.0000 |  39.54 MB |
 RunEmit | SerializeOnly | 193.0 ms |  2.448 ms |  2.044 ms |  2000.0000 | 1000.0000 |  17.08 MB |

You can ignore the timing differences in the benchmark here, that's just noise on my machine. The
benchmark won't reflect larger GC costs because usually no collections are done during the
benchmark runs. (Benchmark.NET calls GC.Collect() after each run)

…Emit

After I added support for measuring allocations in the compiler
benchmark suite I noticed in a PerfView trace that we were often
resizing the arrays we used for the Emit tables. Looking more closely at
how we allocate the tables, I found that we were using an approximation
that was very close to the actual size of the tables needed, but
systemically undercounted. Ironically, this may be worse than being
farther off since it meant that we were getting right to the edge of
available space, before requiring a resize, meaning a new large
allocation, and copies from all of the entries in the old tables to the
new tables.

By applying a multiplier to the table size and allocating more memory
for the tables, I've actually decreased the total amount of memory
allocated during emit.
@agocke agocke requested review from a team as code owners August 21, 2018 03:56
@agocke agocke requested a review from jaredpar August 21, 2018 03:56
@agocke
Copy link
Copy Markdown
Member Author

agocke commented Aug 22, 2018

@dotnet/roslyn-compiler For a one line compiler change.

@agocke
Copy link
Copy Markdown
Member Author

agocke commented Aug 27, 2018

ping @dotnet/roslyn-compiler for review

@agocke agocke merged commit 6ceac49 into dotnet:master Aug 30, 2018
@agocke agocke deleted the fix-nummethods-heuristic branch August 30, 2018 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants