perf: escape query components in place - #2277
Conversation
- Replace the generated interpolation change with direct query-buffer escaping. - Preserve Unicode behavior and add focused benchmark coverage.
|
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! |
|
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. |
|
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 |
|
Ah, I see, just confusing with the new interpolated string class. Feel free to make a new PR with the new feature. |
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
Additional information
EventPipe GcVerbose, ScalarPairs:
Release builds pass with zero warnings. All 7,437 tests pass.