Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Micro optimization EndsWith using #13084

Merged
merged 4 commits into from
Oct 2, 2023

Conversation

workgroupengineering
Copy link
Contributor

What does the pull request do?

  • Replace ToLowerInvariant().EndsWith with EndsWith("string", StringComparison.OrdinalIgnoreCase)
  • Replace value.EndsWith("%") with value[value.Length -1 ] == '%'

What is the current behavior?

What is the updated/expected behavior with this PR?

small decrease in memory usage during build

How was the solution implemented (if it's not obvious)?


BenchmarkDotNet v0.13.8, Windows 10 (10.0.19045.3448/22H2/2022Update)
Intel Core i5-10400 CPU 2.90GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK 7.0.401
  [Host]     : .NET 6.0.22 (6.0.2223.42425), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.22 (6.0.2223.42425), X64 RyuJIT AVX2


Method Mean Error StdDev Median Ratio Gen0 Allocated Alloc Ratio
ToLowerInvariant_EndsWith 193.712 ms 3.3250 ms 3.1102 ms 193.146 ms 1.00 6000.0000 38600893 B 1.000
EndsWith_With_StringComparison 3.959 ms 0.2222 ms 0.6411 ms 3.761 ms 0.02 - 2 B 0.000

BenchmarkDotNet v0.13.8, Windows 10 (10.0.19045.3448/22H2/2022Update)
Intel Core i5-10400 CPU 2.90GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK 7.0.401
  [Host]     : .NET 6.0.22 (6.0.2223.42425), X64 RyuJIT AVX2
  DefaultJob : .NET 6.0.22 (6.0.2223.42425), X64 RyuJIT AVX2


Method Mean Error StdDev Median Ratio RatioSD Allocated Alloc Ratio
InvariantCultureIgnoreCase 4.064 ms 0.2365 ms 0.6935 ms 3.874 ms 1.00 0.00 2 B 1.00
OrdinalIgnoreCase 1.490 ms 0.0280 ms 0.0691 ms 1.457 ms 0.36 0.06 1 B 0.50

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@workgroupengineering workgroupengineering marked this pull request as ready for review September 30, 2023 10:51
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0040249-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For EndsWith with a single char, .NET Core 2+ and .NET Standard 2.1 already have an optimized String.EndsWith(char).

Since we still need to target .NET Standard 2.0, can you please add its equivalent with conditional compilation to StringCompatibilityExtensions and use it instead? This way we get the framework built-in one in .NET 6+ and we'll be able to easily remove the polyfill later without any other change.

src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj Outdated Show resolved Hide resolved
src/Shared/StringCompatibilityExtensions.cs Outdated Show resolved Hide resolved
@maxkatz6 maxkatz6 enabled auto-merge October 1, 2023 22:34
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0040342-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Oct 2, 2023
Merged via the queue into AvaloniaUI:master with commit af254d5 Oct 2, 2023
5 checks passed
@workgroupengineering workgroupengineering deleted the perf/EndsWith branch October 2, 2023 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants