date optimization#1658
Open
luigi617 wants to merge 2 commits into
Open
Conversation
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.
Summary
AwsSigningConfigto avoid repeatedInstant.format()calls during SigV4 signingfillInStackTraceon internal parser exceptions to eliminate expensive JVM stack walks during RFC-5322 date parsingMotivation
Profiling sequential DynamoDB latency benchmarks revealed two date-related hotspots in the per-request signing and response handling paths:
Repeated date formatting:
Instant.format(TimestampFormat.ISO_8601_CONDENSED)was called 6 times per signing operation (instringToSign,credentialScope,signingKey, andcanonicalRequest), each time producing the same string from the sameInstant.Exception-driven date parsing: The
ClockSkewInterceptorparses the responseDateheader on every request viaInstant.fromRfc5322(). The parser combinator'saltfunction uses exceptions for backtracking — matching the day name "Thu" requires throwing and catching 3ParseExceptioninstances (for "Mon", "Tue", "Wed"). Each exception triggersThrowable.fillInStackTrace(), a native JNI call that walks the entire thread stack (~50+ frames deep in coroutine + middleware context), costing ~5-15µs per exception.What changed
Date formatting (signing path):
AwsSigningConfignow exposesformattedSigningDateandformattedSigningDateShortproperties, computed once at construction. All 6 call sites inBaseSigV4SignatureCalculator,Canonicalizer,RequestMutator, andSigV4SignatureCalculatoruse the pre-computed values.Date parsing (response path):
Introduced
NoTraceParseExceptionas anexpect/actualclass:fillInStackTrace()to returnthis(no-op)All internal parser combinator throw sites (
char(),tag(),oneOf(),takeMNDigitsT(),mnDigitsInRange(),fraction()) now throwNoTraceParseException. The finalaltfailure that may escape to user code retains the fullParseExceptionwith stack trace for diagnosability.Benchmark Results
All benchmarks run on m7i.2xlarge instances with the following configuration:
E2E Latency (DynamoDB)
14 paired instances (base and target on same host).
DynamoDB PutItem
DynamoDB GetItem
Latency observations:
ClockSkewInterceptorparses theDateheader) represents a larger fraction of the shorter GET latencyE2E Throughput (S3)
This optimization targets per-request fixed costs (date format/parse), which are negligible relative to the I/O and crypto costs that dominate high-concurrency throughput workloads. No meaningful throughput change expected or observed.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.