Skip to content

Commit eb6c331

Browse files
thcedclaude
andcommitted
perf: Precompute Parameter JSON-pointer at parse time (W5)
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>
1 parent 7889d92 commit eb6c331

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/main/java/com/retailsvc/http/internal/RequestPreparationFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private void validateParameters(
102102
HttpExchange exchange, Operation op, Map<String, String> pathParams) {
103103
Map<String, String> query = null;
104104
for (Parameter p : op.parameters()) {
105-
String pointer = "/" + p.in().name().toLowerCase(Locale.ROOT) + "/" + p.name();
105+
String pointer = p.pointer();
106106
if (p.in() == Parameter.Location.QUERY && query == null) {
107107
query = parseQuery(exchange.getRequestURI().getQuery());
108108
}

src/main/java/com/retailsvc/http/spec/Parameter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.retailsvc.http.spec;
22

33
import com.retailsvc.http.spec.schema.Schema;
4+
import java.util.Locale;
5+
6+
public record Parameter(String name, Location in, boolean required, Schema schema, String pointer) {
7+
8+
public Parameter(String name, Location in, boolean required, Schema schema) {
9+
this(name, in, required, schema, "/" + in.name().toLowerCase(Locale.ROOT) + "/" + name);
10+
}
411

5-
public record Parameter(String name, Location in, boolean required, Schema schema) {
612
public enum Location {
713
PATH,
814
QUERY,

0 commit comments

Comments
 (0)