Skip to content

perf: escape query components in place - #2277

Merged
glennawatson merged 4 commits into
reactiveui:mainfrom
jgarciadelanoceda:perf_StringInterpolationInQueryParams
Jul 25, 2026
Merged

perf: escape query components in place#2277
glennawatson merged 4 commits into
reactiveui:mainfrom
jgarciadelanoceda:perf_StringInterpolationInQueryParams

Conversation

@jgarciadelanoceda

@jgarciadelanoceda jgarciadelanoceda commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

What kind of change does this PR introduce?

Performance improvement.

What is the new behavior?

ASCII query keys and values are escaped directly into the pooled query buffer. Non-ASCII text uses framework escaping.

What is the current behavior?

Query escaping creates temporary strings before copying them into the final query buffer.

What might this PR break?

None.

Checklist

  • I have read the Contribute guide
  • Tests have been added or updated
  • Docs have been added or updated
  • Changes target the main branch
  • PR title follows Conventional Commits

Additional information

EventPipe GcVerbose, ScalarPairs:

  • 192 B to 120 B per operation
  • 116.4 ns to 102.5 ns
  • Gen0 0.0114 to 0.0072

Release builds pass with zero warnings. All 7,437 tests pass.

Comment thread src/InterfaceStubGenerator.Shared/Emitter.cs Outdated
jgarciadelanoceda and others added 2 commits July 25, 2026 11:59
- Replace the generated interpolation change with direct query-buffer escaping.
- Preserve Unicode behavior and add focused benchmark coverage.
@glennawatson glennawatson changed the title perf:Generate stringInterpolation In Query params perf: escape query components in place Jul 25, 2026
@glennawatson

Copy link
Copy Markdown
Contributor

Thanks for the contribution. Benchmarking found identical IL and a brace regression. I used this PR for a measured query escaping improvement: 192 B to 120 B and 116.4 ns to 102.5 ns, so you still get credit. Every bit helps. Thanks!

@glennawatson
glennawatson enabled auto-merge (squash) July 25, 2026 12:52
@glennawatson
glennawatson disabled auto-merge July 25, 2026 12:58
@glennawatson
glennawatson enabled auto-merge (squash) July 25, 2026 12:58
@glennawatson
glennawatson disabled auto-merge July 25, 2026 13:04
@glennawatson
glennawatson merged commit 2f16caa into reactiveui:main Jul 25, 2026
13 checks passed
@glennawatson

Copy link
Copy Markdown
Contributor

I'll include this in the next release once we got a couple more fixes in. Sent you a invite for write permissions to the repo, which allows you to contribute directly on the repo rather than a fork.

@jgarciadelanoceda

Copy link
Copy Markdown
Collaborator Author

I run the NullableIndexedCollectionGeneratesInline test case and what I tried to do in the PR was avoiding the source-generated file to be generated with string concatenation. This is a sample of what it produced:

refitQueryBuilder.AddPreEscapedKey(refitQueryValue_key + "." + "Id", refitUseDefaultFormatting ? (global::Refit.GeneratedRequestRunner.FormatInvariant(refitQueryValue_items_Id, null)) : global::Refit.GeneratedRequestRunner.FormatUrlParameter(refitSettings, refitQueryValue_items_Id, ______itemsAttributeProvider, typeof(global::System.Collections.Generic.IReadOnlyList<global::RefitGeneratorTest.Item>)), false);

I wanted to do just:

refitQueryBuilder.AddPreEscapedKey($"{refitQueryValue_key}.Id", refitUseDefaultFormatting ? (global::Refit.GeneratedRequestRunner.FormatInvariant(refitQueryValue_items_Id, null)) : global::Refit.GeneratedRequestRunner.FormatUrlParameter(refitSettings, refitQueryValue_items_Id, ______itemsAttributeProvider, typeof(global::System.Collections.Generic.IReadOnlyList<global::RefitGeneratorTest.Item>)), false);

Sorry I did not explain myself on the PR. When the user that is using Refit it could avoid an string concatenation

@glennawatson

Copy link
Copy Markdown
Contributor

Ah, I see, just confusing with the new interpolated string class. Feel free to make a new PR with the new feature.

@jgarciadelanoceda
jgarciadelanoceda deleted the perf_StringInterpolationInQueryParams branch July 27, 2026 07:29
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