perf: avoid MeasurementUnit enum boxing allocations #5218
1 issue
find-bugs: Found 1 issue (1 high)
High
GetPredefinedName returns PascalCase names instead of lowercase, changing serialized output - `src/Sentry/MeasurementUnit.cs:22-26`
The new implementation uses Enum.GetNames<Duration>() (etc.) to precompute names, but Enum.GetNames<T>() returns names exactly as declared in the enum (PascalCase like "Second", "Byte", "Percent"). The previous implementation used _unit.ToString().ToLowerInvariant() which lowercased them. This regresses the public serialized form sent to Sentry from e.g. "second" to "Second", breaks existing tests (MeasurementUnitTests asserts "second"/"byte"/"percent"), and changes what Sentry receives via ToString()/ToNullableString(). The PR claims tests pass, but CanUseDurationUnits, CanUseInformationUnits, and CanUseFractionUnits would all fail with this code.
Also found at:
src/Sentry/MeasurementUnit.cs:109-111
⏱ 1m 5s · 249.3k in / 4.3k out · $1.49 (+verification: $1.09, +merge: $0.00)
Annotations
Check failure on line 26 in src/Sentry/MeasurementUnit.cs
sentry-warden / warden: find-bugs
GetPredefinedName returns PascalCase names instead of lowercase, changing serialized output
The new implementation uses `Enum.GetNames<Duration>()` (etc.) to precompute names, but `Enum.GetNames<T>()` returns names exactly as declared in the enum (PascalCase like "Second", "Byte", "Percent"). The previous implementation used `_unit.ToString().ToLowerInvariant()` which lowercased them. This regresses the public serialized form sent to Sentry from e.g. "second" to "Second", breaks existing tests (MeasurementUnitTests asserts "second"/"byte"/"percent"), and changes what Sentry receives via `ToString()`/`ToNullableString()`. The PR claims tests pass, but `CanUseDurationUnits`, `CanUseInformationUnits`, and `CanUseFractionUnits` would all fail with this code.
Check failure on line 111 in src/Sentry/MeasurementUnit.cs
sentry-warden / warden: find-bugs
[9AB-NUT] GetPredefinedName returns PascalCase names instead of lowercase, changing serialized output (additional location)
The new implementation uses `Enum.GetNames<Duration>()` (etc.) to precompute names, but `Enum.GetNames<T>()` returns names exactly as declared in the enum (PascalCase like "Second", "Byte", "Percent"). The previous implementation used `_unit.ToString().ToLowerInvariant()` which lowercased them. This regresses the public serialized form sent to Sentry from e.g. "second" to "Second", breaks existing tests (MeasurementUnitTests asserts "second"/"byte"/"percent"), and changes what Sentry receives via `ToString()`/`ToNullableString()`. The PR claims tests pass, but `CanUseDurationUnits`, `CanUseInformationUnits`, and `CanUseFractionUnits` would all fail with this code.