Skip to content

Commit 4b7e32a

Browse files
thcedclaude
andcommitted
perf: Add Request.current() escape hatch (W7)
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>
1 parent eb6c331 commit 4b7e32a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/main/java/com/retailsvc/http/Request.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ public final class Request {
2121

2222
private Request() {}
2323

24+
/**
25+
* Returns the full per-request context. Use this when a handler reads more than one field — every
26+
* call to {@link #bytes()}, {@link #parsed()}, {@link #operationId()}, or {@link #pathParams()}
27+
* walks the JDK's scope chain independently, so reading via {@code current()} once is cheaper.
28+
*/
29+
public static RequestContext current() {
30+
return CONTEXT.get();
31+
}
32+
2433
public static byte[] bytes() {
2534
return CONTEXT.get().body();
2635
}

0 commit comments

Comments
 (0)