This repository was archived by the owner on Jul 22, 2026. It is now read-only.
Fix dark cluster URI rewrite deopt storm consuming 80% CPU - #1160
Closed
jcleezer wants to merge 6 commits into
Closed
Fix dark cluster URI rewrite deopt storm consuming 80% CPU #1160jcleezer wants to merge 6 commits into
jcleezer wants to merge 6 commits into
Conversation
added 4 commits
April 7, 2026 17:44
…append(String) is an intrinsic, a single System.arraycopy - No bimodal branching — no speculative optimization to get wrong - Monomorphic call sites — StringBuilder.append and URI.create are stable JIT targets with no polymorphic dispatch
Instead of bypassing UriBuilder entirely with a skipReEncoding flag and raw StringBuilder assembly in D2URIRewriter, add a replaceQueryFrom(URI) method to UriBuilder that copies the raw query directly. This puts the fix in the right layer so any caller doing URI rewriting benefits. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
The linkedin/rest.li repository is being archived - see #1178 for details. Ahead of it's archiving, we are closing all issues and PRs. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
UriBuilder.replaceQueryFrom(URI)that copies the raw (already percent-encoded) query string directly from a source URI, bypassing the expensive character-by-characterUriComponent._encodeloop.D2URIRewriterto use the new method — removes theskipReEncodingflag, 2-arg constructor, andrewriteURIFromRawworkaround.DarkClusterManagerImplto use the simplified single-argD2URIRewriterconstructor.Problem
Production profiling shows
DarkClusterFilter.onRestRequest→DarkClusterManagerImpl.rewriteRequest→D2URIRewriter.rewriteURI→UriBuilder.replaceQuery→UriComponent._encodeconsuming ~82% of total CPU.The root cause:
replaceQuery(d2Uri.getRawQuery())passes an already percent-encoded query string into_encode, which iterates every character viacodePointAtonly to leave them unchanged. For large query strings this is devastating,especially under JIT deoptimization.
Fix
Rather than bypassing
UriBuilderentirely (the previousskipReEncodingapproach), this puts the fix in the right layer:UriBuilder.replaceQueryFrom(URI)copiesuri.getRawQuery()directly into the builder's internalqueryfield —which already expects percent-encoded values (see
UriBuilder.uri()lines 202-206 which do the same thing).This means:
D2URIRewriterUriBuilderD2URIRewritergoes back to being a simple, single-path classTest plan
UriBuilder.replaceQueryFrom(URI)tested via existingUriComponentTestsuiteTestD2URIRewriter— simple rewrite, encoded queries, no query, fragment, exhaustive ASCII character preservationTestDarkClusterUrlRewrite— basic rewrite, query params, encoded query params./gradlew :li-jersey-uri:test :d2:test --tests TestD2URIRewriter :darkcluster:test --tests TestDarkClusterUrlRewritepasses