Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

stephentoub
Copy link
Member

Remove some boxing from tuples with >= 8 elements

Take advantage of #14698 to avoid boxing the TRest argument and improve devirtualization.

Method Toolchain Mean Error Ratio Allocated
GHC7 Old 2.043 ns 0.0100 ns 1.00 -
GHC7 New 2.042 ns 0.0135 ns 1.00 -
GHC8 Old 8.489 ns 0.0917 ns 1.00 24 B
GHC8 New 3.230 ns 0.0159 ns 0.38 -
GHC9 Old 9.062 ns 0.0459 ns 1.00 24 B
GHC9 New 3.230 ns 0.0194 ns 0.36 -
GHC10 Old 9.644 ns 0.1006 ns 1.00 32 B
GHC10 New 3.479 ns 0.0161 ns 0.36 -
ToString7 Old 214.852 ns 0.4342 ns 1.00 208 B
ToString7 New 209.641 ns 0.5081 ns 0.98 208 B
ToString8 Old 257.0 ns 4.019 ns 1.00 280 B
ToString8 New 242.9 ns 2.952 ns 0.95 256 B
ToString9 Old 268.936 ns 1.0210 ns 1.00 288 B
ToString9 New 266.940 ns 0.9469 ns 0.99 264 B
ToString10 Old 318.626 ns 0.9727 ns 1.00 416 B
ToString10 New 307.865 ns 1.2496 ns 0.97 384 B
Index7 Old 4.067 ns 0.0813 ns 1.00 24 B
Index7 New 3.988 ns 0.0256 ns 0.98 24 B
Index8 Old 7.906 ns 0.0354 ns 1.00 48 B
Index8 New 5.134 ns 0.0505 ns 0.65 24 B
Index9 Old 7.607 ns 0.0418 ns 1.00 48 B
Index9 New 4.996 ns 0.0926 ns 0.66 24 B
Index10 Old 8.989 ns 0.0542 ns 1.00 56 B
Index10 New 5.113 ns 0.0422 ns 0.57 24 B
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Runtime.CompilerServices;

[MemoryDiagnoser]
public class Program
{
    public static void Main(string[] args) => BenchmarkSwitcher.FromTypes(new[] { typeof(Program) }).Run(args);

    private (int, int, int, int, int, int, int) _v7 = (1, 2, 3, 4, 5, 6, 7);
    private (int, int, int, int, int, int, int, int) _v8 = (1, 2, 3, 4, 5, 6, 7, 8);
    private (int, int, int, int, int, int, int, int, int) _v9 = (1, 2, 3, 4, 5, 6, 7, 8, 9);
    private (int, int, int, int, int, int, int, int, int, int) _v10 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

    [Benchmark] public int GHC7() => _v7.GetHashCode();
    [Benchmark] public int GHC8() => _v8.GetHashCode();
    [Benchmark] public int GHC9() => _v9.GetHashCode();
    [Benchmark] public int GHC10() => _v10.GetHashCode();

    [Benchmark] public string ToString7() => _v7.ToString();
    [Benchmark] public string ToString8() => _v8.ToString();
    [Benchmark] public string ToString9() => _v9.ToString();
    [Benchmark] public string ToString10() => _v10.ToString();

    [Benchmark] public object Index7() => ((ITuple)_v7)[6];
    [Benchmark] public object Index8() => ((ITuple)_v8)[7];
    [Benchmark] public object Index9() => ((ITuple)_v9)[8];
    [Benchmark] public object Index10() => ((ITuple)_v10)[9];
}

cc: @AndyAyersMS, @jcouv

Copy link
Member

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit in spacing of the comments

@stephentoub stephentoub force-pushed the vtboxing branch 2 times, most recently from f0fbffc to cb1e8b9 Compare September 9, 2019 14:06
@adamsitnik adamsitnik added the tenet-performance Performance related issue label Sep 10, 2019
Take advantage of dotnet#14698 to avoid boxing the TRest argument and improve devirtualization.
@stephentoub stephentoub merged commit 3f678ae into dotnet:master Sep 15, 2019
@stephentoub stephentoub deleted the vtboxing branch September 15, 2019 01:37
Dotnet-GitSync-Bot pushed a commit to Dotnet-GitSync-Bot/corefx that referenced this pull request Sep 15, 2019
Take advantage of dotnet/coreclr#14698 to avoid boxing the TRest argument and improve devirtualization.

Signed-off-by: dotnet-bot <[email protected]>
Dotnet-GitSync-Bot pushed a commit to Dotnet-GitSync-Bot/corert that referenced this pull request Sep 15, 2019
Take advantage of dotnet/coreclr#14698 to avoid boxing the TRest argument and improve devirtualization.

Signed-off-by: dotnet-bot <[email protected]>
Dotnet-GitSync-Bot pushed a commit to Dotnet-GitSync-Bot/mono that referenced this pull request Sep 15, 2019
Take advantage of dotnet/coreclr#14698 to avoid boxing the TRest argument and improve devirtualization.

Signed-off-by: dotnet-bot <[email protected]>
danmoseley pushed a commit to dotnet/corefx that referenced this pull request Sep 15, 2019
Take advantage of dotnet/coreclr#14698 to avoid boxing the TRest argument and improve devirtualization.

Signed-off-by: dotnet-bot <[email protected]>
MichalStrehovsky pushed a commit to dotnet/corert that referenced this pull request Sep 15, 2019
Take advantage of dotnet/coreclr#14698 to avoid boxing the TRest argument and improve devirtualization.

Signed-off-by: dotnet-bot <[email protected]>
vargaz pushed a commit to mono/mono that referenced this pull request Sep 15, 2019
…) (#16844)

Take advantage of dotnet/coreclr#14698 to avoid boxing the TRest argument and improve devirtualization.

Signed-off-by: dotnet-bot <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants