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

Conversation

@stephentoub
Copy link
Member

  • Seal some internal overrides
  • In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).

Related to https://github.com/dotnet/corefx/issues/30382

cc: @jkotas, @roji, @tarekgh, @krwq

- Seal some internal overrides
- In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).
@stephentoub
Copy link
Member Author

Example microbenchmark:

using System;
using System.Diagnostics;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes.Jobs;

[MemoryDiagnoser]
[InProcess]
public class Benchmarks
{
    private static void Main() => BenchmarkRunner.Run<Benchmarks>();

    private char[] _chars = "hello world".ToCharArray();
    private byte[] _bytes = new byte[100];

    [Benchmark]
    public void EncodingUTF8GetBytes()
    {
        ReadOnlySpan<char> src = _chars;
        Span<byte> dst = _bytes;
        for (int i = 0; i < 1000; i++)
        {
            Encoding.UTF8.GetBytes(src, dst);
        }
    }
}
Method Mean Error StdDev Allocated
Before 21.43 us 0.1606 us 0.1502 us 0 B
After 19.53 us 0.1589 us 0.1409 us 0 B

@jkotas jkotas merged commit acd35fd into dotnet:master Jun 15, 2018
dotnet-bot pushed a commit to dotnet/corefx that referenced this pull request Jun 15, 2018
- Seal some internal overrides
- In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).

Signed-off-by: dotnet-bot-corefx-mirror <[email protected]>
@stephentoub stephentoub deleted the encodingdispatch branch June 15, 2018 22:17
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request Jun 16, 2018
- Seal some internal overrides
- In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).

Signed-off-by: dotnet-bot <[email protected]>
stephentoub added a commit to dotnet/corert that referenced this pull request Jun 16, 2018
- Seal some internal overrides
- In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).

Signed-off-by: dotnet-bot <[email protected]>
stephentoub added a commit to dotnet/corefx that referenced this pull request Jun 16, 2018
- Seal some internal overrides
- In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).

Signed-off-by: dotnet-bot-corefx-mirror <[email protected]>
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
- Seal some internal overrides
- In the more common encodings, add overrides of GetBytes/GetByteCount/GetChars/GetCharCount to avoid another layer of virtuals from the base class (they can call to an internal non-virtual).

Commit migrated from dotnet/coreclr@acd35fd
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants