dotnet / dotnet/performance

Improve granularity of Perf.Utf8Encoding.cs tests

Open
#1,512 4 comments 2 reactions 0 assignees View on GitHub
Dominant language
F#
Stars
773
Forks
301
Avg merge
6d 9h
Merged PRs (30d)
15

Description

Per the magic decoder ring at https://github.com/dotnet/runtime/issues/41699#issuecomment-689714126, some of the tests in [__Perf.Utf8Encoding.cs__](https://github.com/dotnet/performance/blob/adccb815003451dd68586516d4f25f52f3f2ebe7/src/benchmarks/micro/libraries/System.Text.Encoding/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, Span)`, which exercises only `Utf8Utility.TranscodeToUtf16` (transcoding).
4. A test which calls `Encoding.UTF8.GetBytes(ROS, Span)`, 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.