Skip to content

Perf/sdk internal processing v2#46

Open
xinlian12 wants to merge 4 commits into
mainfrom
perf/sdk-internal-processing-v2
Open

Perf/sdk internal processing v2#46
xinlian12 wants to merge 4 commits into
mainfrom
perf/sdk-internal-processing-v2

Conversation

@xinlian12
Copy link
Copy Markdown
Owner

No description provided.

Annie Liang and others added 4 commits March 31, 2026 18:23
Eliminate per-response intermediate HashMap allocation by adding a new
StoreResponse constructor that accepts HttpHeaders directly. Header names
and values are populated into String[] arrays without materializing an
intermediate Map. The JsonNodeStorePayload is updated to accept header
arrays and only builds a Map lazily on error paths (extremely rare).

Pre-size HashMaps throughout the hot path to avoid resize/rehash:
- HttpHeaders request construction: sized to defaultHeaders + request headers
- StoreResponse.replicaStatusList: pre-sized to 4
- StoreResponse.withRemappedStatusCode: pre-sized to header count
- RxDocumentServiceRequest fallback maps: pre-sized to 32

Fix HttpUtils.asMap() double-allocation by iterating HttpHeaders directly
instead of calling toMap() which creates an intermediate HashMap.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Case fast-path

Change 1: Replace vendored UnmodifiableList with Collections.unmodifiableList()
- UnmodifiableList wraps via 4-level virtual dispatch chain
  (UnmodifiableList -> AbstractSerializableListDecorator ->
   AbstractListDecorator -> AbstractCollectionDecorator)
- AbstractListDecorator.decorated() called on every list operation
  accounts for ~1.02% CPU (398 samples at 1t-c128)
- Collections.unmodifiableList() returns a simple wrapper that
  JIT can inline efficiently

Change 2: Add isAsciiLowerCase fast-path in HttpHeaders
- HTTP/2 headers are already lowercase per protocol spec
- Most x-ms-* custom headers are already lowercase
- Skip String.toLowerCase(Locale.ROOT) when string is already
  all-lowercase via simple char range check
- StringLatin1.toLowerCase accounts for ~1.29% CPU (500 samples)

Files changed:
- LocationCache.java: field types + return types + constructors
- GlobalEndpointManager.java: return types
- ClientRetryPolicy.java: variable type
- GlobalPartitionEndpointManagerForPerPartitionCircuitBreaker.java: variable types
- HttpHeaders.java: set() and getHeader() fast-path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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