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

   This PR implements an optimisation for the Interval.toString method.
   
   Based on the flame graph before optimisation, we can see that the toString 
method takes up a significant amount of the running time (~16%). After the 
optimisation, the optimised format method only accounts for ~4% of the running 
time.
   
   We use the algorithm found 
[here](https://howardhinnant.github.io/date_algorithms.html#civil_from_days) in 
order to optimise the toString method. 
   
   The implementation differs slightly as we know Druid's intervals. As such 
the following tweaks have been made:
   
   - We fix era to be 5 since we know the dates will be within 
[2000-03-01T00:00:00.000Z, 2400-02-29T23:59:59.999Z]
   - We omit any negative dates checks.
   
   Any dates which do not fall within the era or doesn't have UTC timezone will 
use `Interval.toString()` as the fallback.
   
   ```
   Benchmark                                                              Mode  
Cnt  Score   Error  Units
   DefaultQueryMetricsBenchmark.baselineMetrics                           avgt  
 40  1.207 ± 0.022  us/op
   DefaultQueryMetricsBenchmark.withCustomIntervalToStringDimension       avgt  
 40  0.413 ± 0.010  us/op
   ```
   
   Note: I do agree that the code is difficult to understand and there are 
magic numbers still existing. I did my best to refactor most of the numbers to 
variables if they were constants and I've also tried to maintain the same 
structure as the algorithm provided in order to make it easier to understand. 
   
   ## Flame Graph before Optimisation
   <img width="2830" height="1274" alt="image" 
src="https://github.com/user-attachments/assets/bd61ead5-8798-4624-bcf8-4dfed9e071a4";
 />
   
   ## Flame Graph after Optimisation
   <img width="3000" height="1492" alt="image" 
src="https://github.com/user-attachments/assets/3470432b-cb4e-48a5-b8dc-af805495f49e";
 />
   
   


-- 
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