schlosna commented on a change in pull request #352:
URL: 
https://github.com/apache/httpcomponents-client/pull/352#discussion_r814961372



##########
File path: 
httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
##########
@@ -45,7 +45,29 @@ public static long getNextExecNumber() {
     }
 
     public static String getNextExchangeId() {
-        return String.format("ex-%010d", COUNT.incrementAndGet());
+        return createId(COUNT.incrementAndGet());
+    }
+
+    /**
+     * Create an exchange ID.
+     *
+     * Hand rolled equivalent to `String.format("ex-%010d", value)` optimized 
to reduce
+     * allocation and CPU overhead.
+     */
+    static String createId(long value) {
+        String longString = Long.toString(value);
+        return "ex-" + zeroPad(10 - longString.length()) + longString;

Review comment:
       Copying over @carterkozak 's updated benchmarks from 
https://github.com/schlosna/httpclient-format-performance/pull/1
   
   JDK17 results
   ```
   Benchmark                               Mode  Cnt    Score    Error  Units
   FormatBenchmarks.stringFormat           avgt    5  431.935 ± 37.370  ns/op
   FormatBenchmarks.zeroPadPrefixesArray   avgt    5   38.261 ±  1.599  ns/op
   FormatBenchmarks.zeroPadPrefixesSwitch  avgt    5   26.841 ±  2.509  ns/op
   FormatBenchmarks.zeroPadProposed        avgt    5   39.199 ±  1.526  ns/op
   ```
   
   
   JDK8 results
   ```
   Benchmark                               Mode  Cnt    Score    Error  Units
   FormatBenchmarks.stringFormat           avgt    5  514.358 ± 61.744  ns/op
   FormatBenchmarks.zeroPadPrefixesArray   avgt    5   56.109 ±  2.994  ns/op
   FormatBenchmarks.zeroPadPrefixesSwitch  avgt    5   43.931 ±  6.315  ns/op
   FormatBenchmarks.zeroPadProposed        avgt    5   70.111 ±  5.690  ns/op
   ```




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