Skip to content

Avoid rebuilding clean query strings#2265

Open
pavel-ptashyts wants to merge 2 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/lazy-query-encoding
Open

Avoid rebuilding clean query strings#2265
pavel-ptashyts wants to merge 2 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/lazy-query-encoding

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a lazy query-string encoder that reuses the input String when no escaping is needed
  • use that fast path for existing queries without additional query params
  • add tests for no-op query identity and query escaping

Rationale

UriEncoder already reuses the original Uri when encoding produces equal path and query values, but the existing query path still allocated a StringBuilder and replacement String for clean queries. The new helper mirrors the path encoder's lazy behavior and avoids that temporary allocation in the common already-encoded REST query case.

Validation

  • ./mvnw -pl client -Dtest=Utf8UrlEncoderTest,UriEncoderTest test
  • ./mvnw -pl client -DskipTests compile
  • ./mvnw -pl client -Dtest=UriTest,QueryParametersTest,PostWithQueryStringTest test

Attribution

Codex on behalf of Pavel Ptashyts

@pavel-ptashyts
pavel-ptashyts force-pushed the perf/lazy-query-encoding branch from 2da5f56 to d2086e8 Compare July 20, 2026 08:50
pavel-ptashyts and others added 2 commits July 20, 2026 17:05
Add a lazy query-string encoder that mirrors the existing path encoder
fast path. When a query contains only pass-through characters,
UriEncoder now reuses the original String instead of allocating a
pooled StringBuilder and an equal replacement String.

The append-based path is unchanged for URLs with additional query
params. Existing escaping behavior is preserved for queries that
need percent-encoding.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
The lazy query encoder is an implementation detail used only by
UriEncoder and same-package tests. Publishing it would expand the
supported API without a caller-facing requirement.

Keep the allocation optimization while limiting the helper to its
package.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts
pavel-ptashyts force-pushed the perf/lazy-query-encoding branch from 1e41fb2 to b4badf5 Compare July 20, 2026 15:08
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.

1 participant