Skip to content

perf: Refactor with optimizations#41

Merged
thced merged 8 commits into
masterfrom
perf/optimizations
May 8, 2026
Merged

perf: Refactor with optimizations#41
thced merged 8 commits into
masterfrom
perf/optimizations

Conversation

@thced

@thced thced commented May 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

thced and others added 8 commits May 8, 2026 12:10
Lower com.retailsvc test logging from debug to info to avoid skewing
load-test profiles, ignore perf/ artifacts, and mark the completed
refactor plan as done.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
basePath() was previously recomputed via URI.create on every request
through RequestPreparationFilter.stripBasePath. The result is
spec-static, so promote it to a record component populated in
Spec.from(...). Eliminates ~100 MB of URI allocations and ~26 CPU
samples per JFR run; k6 throughput +2.6% (44.2k -> 45.3k rps),
p95 -40 µs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
validateString recompiled Pattern on every request. Pattern is
immutable and thread-safe; cache compiled instances in a
ConcurrentHashMap keyed by the raw pattern string. Cache is bounded
by the spec's distinct pattern count.

Removes ~215 MB of int[]/Matcher allocations per JFR run and the
~31 CPU samples in validateString.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
resolveSchema/resolveParameter previously rebuilt the component name
via String.substring on every call. Build a Map keyed by the full
$ref string at construction time so resolution is a single lookup
with no per-request allocation.

Removes ~150 MB of String/byte[] allocs per JFR run; tightens the
validator hot path when schemas use \$ref.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
validateParameters previously allocated a HashMap and ran
String.split on every request, even when the operation declared no
query parameters (the common case). Defer the parse to the first
QUERY parameter encountered; routes without query params now skip
the work entirely.

k6 throughput +3.3% (44.1k -> 45.5k rps), p95 -22 us.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The validation pointer "/<in>/<name>" was rebuilt with StringBuilder
on every request per parameter, even though it's spec-static. Promote
it to a record component computed once in the convenience constructor
and read it in RequestPreparationFilter.validateParameters.

k6 throughput +4.6% vs baseline (44.2k -> 46.2k rps), p95 -83 us.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Each Request.bytes()/parsed()/operationId()/pathParams() call walks
the JDK scope chain independently. Document and expose Request.current()
so handlers that read more than one field can hoist the lookup.

Pure addition — no hot-path callers in the library or example code, so
no measured throughput delta on the k6 baseline.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Use LinkedHashMap.newLinkedHashMap(int) for properly-sized init and
reuse the PARAMETER_REF_PREFIX constant in resolveParameterOrParse
instead of duplicating the literal.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented May 8, 2026

Copy link
Copy Markdown

@thced thced merged commit 4c48958 into master May 8, 2026
4 checks passed
@thced thced deleted the perf/optimizations branch May 8, 2026 11:22
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