GWphua opened a new pull request, #18477:
URL: https://github.com/apache/druid/pull/18477

   ### Description
   
   <!-- Describe the goal of this PR, what problem are you fixing. If there is 
a corresponding issue (referenced above), it's not necessary to repeat the 
description here, however, you may choose to keep one summary sentence. -->
   
   <!-- Describe your patch: what did you change in code? How did you fix the 
problem? -->
   
   <!-- If there are several relatively logically separate changes in this PR, 
create a mini-section for each of them. For example: -->
   
   This PR introduces a faster deserialization strategy when dealing with 
Intervals.
   
   #### Motivation
   
   Many Druid JSON payloads represent intervals as 
"YYYY-MM-DD'T'HH:mm:ss.SSSZ/YYYY-MM-DD'T'HH:mm:ss.SSSZ". The general parser 
behind Intervals.of(String) is flexible but performs extra work (branching, 
multiple format probes, allocations). This shows up as a hot spot in flame 
graphs, especially in streaming paths like JsonParserIterator.
   
   <img width="1920" height="958" alt="image" 
src="https://github.com/user-attachments/assets/fdb6fca4-f7a9-45bb-8f6c-bbd4ac901876";
 />
   
   #### Faster deserialization
   Added a fast-path deserializer for `Interval` that works with the common 
interval string representations, and falls back to `Intervals.of(String)` for 
non-matching inputs.
   
   We minimize work done per parse by:
   - Avoid checking if String can be converted into a `ReadableInterval` / 
`ReadWriteableInterval`.
   - Precompiled `DateTimeFormatter` replaces the flexible parser, with fixed 
chronology.
   - Avoid building 2 `DateTime` objects per parse.
   
   #### Benchmarks
   Added a benchmark to test performance of old (legacy) and new (optimized) 
implementation on 2 cases:
   1. The expected interval format
   2. The interval format which causes a fallback to the old implementation. 
(Suffix: Fallback)
   
   ```
   Benchmark                                                 (numValues)  Mode  
Cnt   Score   Error  Units
   JodaIntervalDeserialization.deserializeLegacy                   20000  avgt  
 30  21.466 ± 0.191  ms/op
   JodaIntervalDeserialization.deserializeLegacyFallback           20000  avgt  
 30  13.953 ± 0.249  ms/op
   JodaIntervalDeserialization.deserializeOptimized                20000  avgt  
 30  11.921 ± 0.082  ms/op
   JodaIntervalDeserialization.deserializeOptimizedFallback        20000  avgt  
 30  30.500 ± 0.304  ms/op
   ```
   
   Benchmark shows an estimated 44% speed-up when working with the interval of 
format "YYYY-MM-DD'T'HH:mm:ss.SSSZ/YYYY-MM-DD'T'HH:mm:ss.SSSZ".
   
   However, for other formats, the fallback causes the performance to drop. 
   
   
   
   #### Release note
   Speed up deserialization time of Intervals by >40%
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * 
`processing/src/main/java/org/apache/druid/java/util/common/Intervals.java`
    * `processing/src/main/java/org/apache/druid/jackson/JodaStuff.java`
    * 
`processing/src/test/java/org/apache/druid/java/util/common/IntervalsTest.java`
    * 
`benchmarks/src/test/java/org/apache/druid/benchmark/JodaIntervalDeserialization.java`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not 
all of these items apply to every PR. Remove the items which are not done or 
not relevant to the PR. None of the items from the checklist below are strictly 
necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [x] been self-reviewed.
   - [x] a release note entry in the PR description.
   - [x] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [x] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [x] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [x] been tested in a test Druid cluster.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to