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

Improve performance of hex string parsing in SKColor #2467

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

jwikberg
Copy link
Contributor

Description of Change

Improve performance of hex string parsing in SKColor using spans when available and with fewer allocated strings when spans are not supported.

Benchmark

  • ParseOld is the current implementation for parsing hex strings to SKColor.
  • ParseImproved is the improved parsing logic for platforms/frameworks that don't support spans
  • ParseSpan is the new parsing logic using spans to avoid allocating strings
|        Method |                  Job |              Runtime |          Mean |      Error |     StdDev | Ratio | RatioSD |  Gen 0 | Allocated |
|-------------- |--------------------- |--------------------- |--------------:|-----------:|-----------:|------:|--------:|-------:|----------:|
|      ParseOld |             .NET 6.0 |             .NET 6.0 | 1,663.7469 ns | 32.9390 ns | 43.9727 ns |  1.00 |    0.00 | 1.8501 |   3,872 B |
| ParseImproved |             .NET 6.0 |             .NET 6.0 |   833.2502 ns | 16.1750 ns | 15.1301 ns |  0.50 |    0.02 | 0.5655 |   1,184 B |
|     ParseSpan |             .NET 6.0 |             .NET 6.0 |   507.7845 ns |  3.4736 ns |  3.2492 ns |  0.31 |    0.01 |      - |         - |
|               |                      |                      |               |            |            |       |         |        |           |
|      ParseOld |        .NET Core 3.1 |        .NET Core 3.1 | 1,981.3356 ns | 18.0860 ns | 16.0328 ns |  1.00 |    0.00 | 1.8501 |   3,872 B |
| ParseImproved |        .NET Core 3.1 |        .NET Core 3.1 | 1,172.5769 ns | 23.1321 ns | 31.6635 ns |  0.60 |    0.02 | 0.5646 |   1,184 B |
|     ParseSpan |        .NET Core 3.1 |        .NET Core 3.1 |   786.5793 ns |  2.1876 ns |  1.8267 ns |  0.40 |    0.00 |      - |         - |
|               |                      |                      |               |            |            |       |         |        |           |
|      ParseOld | .NET Framework 4.7.2 | .NET Framework 4.7.2 | 4,420.4635 ns | 26.6690 ns | 24.9462 ns | 1.000 |    0.00 | 2.1973 |   4,622 B |
| ParseImproved | .NET Framework 4.7.2 | .NET Framework 4.7.2 | 3,542.1632 ns | 23.6055 ns | 22.0806 ns | 0.801 |    0.01 | 0.6943 |   1,460 B |

Existing tests for parsing hex strings cover the changes of this PR.

API Changes

None.

Behavioral Changes

None.

Required skia PR

None.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Merged related skia PRs
  • Changes adhere to coding standard
  • Updated documentation

@jwikberg
Copy link
Contributor Author

@dotnet-policy-service agree

@jwikberg jwikberg force-pushed the improve-skcolor-parse branch from eaacd9c to aec15db Compare June 8, 2023 14:30
mattleibow
mattleibow previously approved these changes Jun 14, 2023
@mattleibow
Copy link
Contributor

@jwikberg
Copy link
Contributor Author

I see some parsing tests are failing: https://dev.azure.com/xamarin/public/_build/results?buildId=88527&view=ms.vss-test-web.build-test-results-tab

This should be fixed now

@mattleibow mattleibow merged commit 2e722cc into mono:main Jun 19, 2023
@mattleibow mattleibow added this to the v2.88.4 milestone Jun 19, 2023
@jwikberg jwikberg deleted the improve-skcolor-parse branch August 28, 2023 12:56
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.

2 participants