perf: Refactor with optimizations#41
Merged
Merged
Conversation
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



No description provided.