You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem
In applications with a high number of parallel operations in multiple threads, we measured some performance hot spots:
- date and time formatting and parsing, mainly caused by the ThreadLocal instances around java.text.SimpleDateFormat (that is not thread safe)
- URI encoding when signing requests
Solution
- Use thread-safe a java.time.format.DateTimeFormatter instance, instead of instance-per-thread of SimpleDateFormat using ThreadLocal's
- Tweak uri-encode to avoid the creation of many temporary LazySeq instances, and only compute the fixed set of safe characters once (instead of on every invocation)
Rationale
DateTimeFormatter is thread safe (and more correct), but since the API in aws-api handles java.util.Date instances exclusively, this requires an additional transformation of java.util.Date -> java.time.ZonedDateTime when formatting (and the other way around when parsing). This new transformation should not impact performance negatively, and it avoids a much more expensive object creation of SimpleDateFormat instances.
This change also fixes a latent bug, that returns the wrong parsed timestamp if the remote API includes a ISO 8601 string with more precision than milliseconds. The parser would wrongly consider anything after the `.` as milliseconds, even if there are 6 digits (that represent in fact microseconds). This bug causes parsed timestamp to be off by some minutes
```
; with 2023-01-23T11:59:03.575496Z as input, the old parser considers
; the timestamp has 575496ms, which is obviously wrong (instead of
; truncating to 575ms as the new parser correctly does)
(.plus (Instant/parse "2023-01-23T11:59:03Z") (Duration/ofMillis 575496))
=> #object[java.time.Instant 0x293edc20 "2023-01-23T12:08:38.496Z"]
```
Fails spec with:
The received message has this structure:
The text was updated successfully, but these errors were encountered: