Repository navigation
Use spans to reduce allocations in Essentials - #40783
Conversation
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
/review expert-review |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/review expert-review |
This comment has been minimized.
This comment has been minimized.
Selected Tests
🧪 Test selection — click to expand
🧪 UI tests — nothing to run❌ Could not queue 🧪 Running — nothingNo UI tests run for this PR. 🧪 Device tests — nothing to run❌ Could not queue 🧪 Running — nothingNo device tests run for this PR. ⏭️ Skipped — what neither suite runsUI tests — 77 categories, 4 platforms Platforms not run: Android, iOS, MacCatalyst, Windows Each skipped platform and category is listed as a Device tests — 105 categories, 4 platforms Platforms not run: Android, iOS, MacCatalyst, Windows Each skipped platform and project is listed as a 🤖 Why these tests — AI rationaleUI testsNo rationale provided. Device testsNo rationale provided. Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification. |
08a9a31 to
27de68a
Compare
This comment has been minimized.
This comment has been minimized.
27de68a to
6f75ab4
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The intentional removal of netstandard assets leaves standalone Essentials compatibility and migration paths unvalidated, requiring maintainer evaluation of the tradeoff.
No open issues 🎉
What changed in this PR
This PR reduces temporary allocations in Essentials path validation, location conversion, and query decoding as part of the .NET 12 modernization stack. Maps changes remain outside this layer.
Changes:
- Replace string splitting and intermediate strings with span-based parsing and reusable query-decoding buffers.
- Format locations using invariant-culture
string.Create. - Add 30 regression test cases and benchmarks for three Essentials operations.
| File | Description |
|---|---|
src/Essentials/test/UnitTests/WebUtils_Tests.cs |
Test query decoding, buffer boundaries, and fragment handling. |
src/Essentials/test/UnitTests/LocationTypeConverter_Tests.cs |
Test malformed coordinates, exact formatting, and invariant culture. |
src/Essentials/test/UnitTests/FileSystemUtils_Tests.cs |
Expand path-segment and traversal validation coverage. |
src/Essentials/src/Types/Shared/WebUtils.shared.cs |
Decode query spans with a reusable stack buffer and heap fallback. |
src/Essentials/src/Types/LocationTypeConverter.shared.cs |
Parse coordinate spans and avoid intermediate formatting strings. |
src/Essentials/src/FileSystem/FileSystemUtils.shared.cs |
Validate path segments without allocating a split array. |
src/Core/tests/Benchmarks/Benchmarks/EssentialsMapsBenchmarker.cs |
Benchmark Essentials parsing and path validation. |
Review effort: Balanced
6f75ab4 to
14eb983
Compare
88facea to
ebed120
Compare
ebed120 to
186cec8
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Removing netstandard assets leaves compatibility and migration paths for standalone Essentials consumers unresolved, requiring maintainer review beyond the supplied host-only validation.
No open issues 🎉
Review effort: Balanced
186cec8 to
e694a64
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
e694a64 to
06a732a
Compare
<!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `cc5e8b30c6a4a9e4b9c7ec8fe4802536ef6fb4b7` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 7.5/10 | ↑ Clean rebase onto Essentials `6f75ab472d`; diff is the same five Maps files.<br>↑ On net12.0: 200/200 Map-filtered Controls.Core tests and 19/19 converter tests pass; benchmark project builds with 0 warnings; format check clean.<br>↓ net12 Android MapHandler not compiled locally (NETSDK1139: the installed Android workload targets net11); relies on CI.<br>↓ Benchmark numbers are historical and not rerun; ConvertTo change not benchmarked; CI for this head not inspected. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. This is the final Maps layer of the .NET 12 spans stack. Its immediate base is `simonrozsival-net12-essentials-spans` (#40783), rebased onto that branch's head `6f75ab472d03f5dc70154418240bf2338f098b65`. GitHub native stack registration is handled separately. ### Description of Change <!-- Enter description of the fix in this section --> > [!IMPORTANT] > Reviewers: please weigh the risk of breaking external consumers and dependencies that require netstandard before merging. That compatibility evaluation has not been done in this PR. - Parse MapSpan coordinates through stack-allocated ranges and span-based numeric parsing instead of allocating a split string array and substrings. Exactly-four-part validation, whitespace handling, invariant-culture parsing and exceptions are unchanged. - Build Android polygon/polyline point lists with a pre-sized indexed loop instead of LINQ projection and list growth. - Format `ConvertTo` output with a single `string.Create(CultureInfo.InvariantCulture, ...)` interpolation instead of four separate `ToString(CultureInfo.InvariantCulture)` calls and two concatenated strings. Output order, separators, invariant numeric formatting and `NotSupportedException` for non-`MapSpan` values are unchanged. - Add malformed-input, exact-output, non-invariant-culture and invalid-value converter tests. Add the Maps converter benchmark and project reference, keeping the Essentials benchmarks from the base. Only these five files differ from the immediate base: - `src/Core/maps/src/Converters/MapSpanTypeConverter.cs` - `src/Core/maps/src/Handlers/Map/MapHandler.Android.cs` - `src/Controls/tests/Core.UnitTests/MapSpanTypeConverterTests.cs` - `src/Core/tests/Benchmarks/Benchmarks/EssentialsMapsBenchmarker.cs` (Maps import, field and method only) - `src/Core/tests/Benchmarks/Core.Benchmarks.csproj` (Maps project reference only) #### Benchmark evidence (historical, from the earlier combined-source run) | Operation | Before time | After time | Before allocated | After allocated | | --- | ---: | ---: | ---: | ---: | | `MapSpanTypeConverter.ConvertFrom` | 166.2 ns | 118.4 ns | 488 B | 176 B | These figures are historical. They come from an earlier benchmark of the combined source branch (commit `04fb9f8a71`) and were **not rerun for this PR or this head**. That run's exact runtime was not preserved, so no .NET 12 benchmark runtime is claimed. Short-run timings are noisy, and this split layer was not measured on its own. There is no benchmark evidence for the Android polygon/polyline change, and the `ConvertTo` formatting change was not benchmarked. #### Local validation (head `cc5e8b30c6`) Local SDK: `12.0.100-alpha.1.26551.101`. Portable output TFM: **`net12.0`**. Installed workloads: android, ios and maccatalyst, all on net11 (rc.2) manifests. | Exact command | Result | | --- | --- | | `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false --filter 'FullyQualifiedName~Map' -v:q` | Passed: 200 tests, 0 failed, 0 skipped (net12.0). | | `dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj -p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false --filter 'FullyQualifiedName~MapSpanTypeConverterTests' -v:q` | Passed: 19 tests, 0 failed (net12.0). | | `dotnet build src/Core/tests/Benchmarks/Core.Benchmarks.csproj -p:IncludeAndroidTargetFrameworks=false -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -v:q` | Passed: 0 warnings, 0 errors. Benchmarks were not executed. | | `dotnet build src/Core/maps/src/Maps.csproj -f net12.0-android -p:IncludeIosTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -v:q` | **Blocked:** NETSDK1139 (`android` not recognized for net12.0-android37.0). **`MapHandler.Android.cs` was not compiled locally**, so CI must cover it. | | `dotnet format whitespace <project> --no-restore --verify-no-changes --include <changed .cs files> --verbosity quiet` (Maps, Controls.Core.UnitTests and Core.Benchmarks projects) | Passed (exit 0) for all three. | | `git diff --quiet 94138e4 HEAD -- <Maps source/test files>` | Passed: the rebase left the Maps converter, handler and test content unchanged. | I did not inspect CI for this head. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> N/A — performance work, not a bug fix. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
There was a problem hiding this comment.
🔵 Needs a closer look
The change depends on removing netstandard assets from Essentials, leaving standalone-consumer compatibility and platform builds unvalidated and requiring maintainer evaluation of those integration risks before merge.
No open issues 🎉
Review effort: Balanced
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
6f75ab472d03f5dc70154418240bf2338f098b65↑ All 550 Essentials tests pass on net12.0; unit-test and Release benchmark builds succeed without warnings.
↓ Platform builds and external-consumer compatibility remain unverified; inherited benchmark measurements do not cover the formatting follow-up; CI validation is not complete.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Target Branch
mainnet11, for reviewFor .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge..NET 12 stack: this layer targets
simonrozsival-net12-simplify-xaml-component-registry(#40782), rather than duplicating its prerequisite changes againstmain.Description of Change
Prepared for review following the XamlC removal. Broader discussion and evaluation of external consumers requiring netstandard remain necessary before merging the stack. Essentials is also consumed standalone, so compatibility must be evaluated beyond applications using the full MAUI stack.
Current prerequisite stack, bottom to top: #40775 (drop netstandard) → #40776 (Graphics) → #40778 (Markdig) → #40779 (Core) → #40780 (Controls.Core) → #40782 (Controls.Xaml) → this PR. The former XamlC-removal prerequisite #40608 is now incorporated upstream. This layer's two commits are rebased onto parent
f1dfc0cea27b57c5f26e4d62c16df76d650ca3c0without patch changes.Use spans for relative-path segment validation, latitude/longitude parsing, and query parameter decoding. Query values containing
+use a reusable stack buffer up to 256 characters, with a heap buffer for larger values. FormatLocationTypeConverter.ConvertTooutput withstring.Create(CultureInfo.InvariantCulture, ...), avoiding two intermediate numeric strings while preserving the exact output andNotSupportedExceptionbehavior. Add 30 test cases covering traversal segments, malformed coordinates, exact location formatting, invariant culture, invalid conversion values, query decoding and stack-buffer boundaries. TextToSpeech chunking is intentionally skipped: chunks are strings anyway.This layer contains Essentials only, plus its benchmark methods. The six Essentials files are taken from
04fb9f8a715163e48978e576bdf31c8c33d1b488, plus a follow-up limited toLocationTypeConverter.ConvertToand its tests. The benchmark differs from that source only by omitting the Maps import, field and method. Maps code, Maps tests andCore.Benchmarks.csprojare unchanged; Maps follows in a separate layer.Inherited benchmark measurements — not re-run in this layer, and they do not measure the
ConvertToformatting follow-up. BenchmarkDotNet Release,--job short --inProcess, Apple Silicon; measured on the combined Essentials/Maps source. The exact runtime was not preserved, so no runtime version is claimed. Allocations are reliable; timings are noisy short-run measurements, not guaranteed real-world gains.FileSystemUtils.IsValidRelativePathWebUtils.ParseQueryStringLocationTypeConverter.ConvertFromValidation re-run at the assessed rebased head:
Passed: 0 warnings, 0 errors.
LC_ALL=en_US.UTF-8 dotnet test --project src/Essentials/test/UnitTests/Essentials.UnitTests.csproj --no-build -p:IncludeAndroidTargetFrameworks=false -p:IncludeiOSTargetFrameworks=false -p:IncludeMacCatalystTargetFrameworks=false -p:IncludeWindowsTargetFrameworks=falsePassed on net12.0/arm64: 550 tests, 0 failed, 0 skipped, including the 30 new cases. Local SDK:
12.0.100-alpha.1.26551.101. The old xunit.console v2 invocation failed to loadxunit.abstractions; the parent migrated this test project to xUnit v3/Microsoft.Testing.Platform, so validation now uses its supporteddotnet testrunner. No test failure or source fix was needed.Passed: Release benchmark build has 0 warnings, 0 errors and no Maps reference; range-diff confirms both commits are unchanged; whitespace check is clean.
Previously run before rebase, not re-run:
Passed before rebase: formatting completed; the Essentials source comparison contained only the
LocationTypeConverterfollow-up and its tests. The rebase preserved both patches unchanged. Platform builds, external-consumer compatibility and benchmark execution were not run in this layer. CI is not claimed green: Build Insights is in progress; the requiredci-analysisskill was unavailable for detailed AzDO verification. Ready for human review does not imply ready to merge.Issues Fixed
N/A — performance modernization; no bug issue is claimed fixed.
Let AI finish this PR