Generated code can severely impact runtime of coverlet
FYI https://github.com/coverlet-coverage/coverlet/issues/1573
Something about this way of making TryParse, makes coverlet extremely slow:
public static bool TryParse(
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
string? name,
out global::TestProject1.MyEnum value,
bool ignoreCase,
bool allowMatchingMetadataAttribute)
{
if (ignoreCase)
{
switch (name)
{
case string s when s.Equals(nameof(global::TestProject1.MyEnum.Test000), global::System.StringComparison.OrdinalIgnoreCase):
value = global::TestProject1.MyEnum.Test000;
return true;
Errr... wat 😅 Thanks for the heads up, I assume this is a coverlet issue though... 😄
Yeah, but might consider changing the generated code a bit.
public static bool TryParse(...) {
if (constant)
lotsOfCode1
else
lotsOfCode2
}
will cause the JIT compiler to not be able to inline the constant evaluation because the function is just too big.
A better approach is:
public static bool TryParseIgnoreCase(...) {lotsOfCode1}
public static bool TryParseWithCase(...) {lotsOfCode2}
public static bool TryParse(...) {
if (constant)
return TryParseIgnoreCase(...);
else
return TryParseWithCase(...);
}
The Jit can then replace the call to TryParse to the proper method if ignoreCase is a constant.
Is that really going to make that much difference? Sure it halves the lines inside the method, but if there's 3500 lines of code and sequence points, is it going to make a decisive difference? I mean, we totally could do it, but is it going to solve anything?
Assuming the algorithm they use scale as O(n^2), halfing the number of code points would be same as cutting runtime to the squareroot. That's pretty significant.
Finally got around to making a PR to split the TryParse method as you suggested - hopefully that fixes the issue!