Skip to content

Improve granularity of Perf.Utf8Encoding.cs tests #1512

@GrabYourPitchforks

Description

@GrabYourPitchforks

Per the magic decoder ring at dotnet/runtime#41699 (comment), some of the tests in Perf.Utf8Encoding.cs may be testing too many concepts, which can complicate finding regressions.

I'd recommend reworking this file so that it contains a total of six tests:

  1. A test which calls Encoding.UTF8.GetByteCount(string), which exercises only Utf16Utility.GetPointerToFirstInvalidChar (validation).
  2. A test which calls Encoding.UTF8.GetCharCount(byte[]), which exercises only Utf8Utility.GetPointerToFirstInvalidByte (validation).
  3. A test which calls Encoding.UTF8.GetChars(ROS<byte>, Span<char>), which exercises only Utf8Utility.TranscodeToUtf16 (transcoding).
  4. A test which calls Encoding.UTF8.GetBytes(ROS<char>, Span<byte>), which exercises only Utf8Utility.TranscodeToUtf8 (transcoding).
  5. A test which calls Encoding.UTF8.GetBytes(string); which exercises validation, byte array instantiation, and transcoding.
  6. A test which calls Encoding.UTF8.GetString(byte[]), which exercises validation, string instantiation, and transcoding.

For each of these tests, we should use Encoding.UTF8.Xyz, allowing the JIT's full devirtualization features to kick in.

/cc @adamsitnik @jeffhandley @kunalspathak @carlossanlop @pgovind @tannergooding

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions