You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by GitBox <gi...@apache.org> on 2022/02/25 16:16:30 UTC

[GitHub] [httpcomponents-client] schlosna commented on a change in pull request #352: Optimize ExecSupport.getNextExchangeId()

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



##########
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:
       Testing pregenerated prefixes via https://github.com/schlosna/httpclient-format-performance/commit/5c3d850ae997b58f73e5dc9170b335fa0bd0276a doesn't actually seem worth the extra complexity
   
   JDK 17.0.1, OpenJDK 64-Bit Server VM, 17.0.1+12-LTS
   ```
   Benchmark                                                       Mode  Cnt     Score     Error   Units
   FormatBenchmarks.stringFormat                                   avgt    5   872.268 ±  13.531   ns/op
   FormatBenchmarks.stringFormat:·gc.alloc.rate                    avgt    5  1311.906 ±  20.298  MB/sec
   FormatBenchmarks.stringFormat:·gc.alloc.rate.norm               avgt    5  1400.112 ±   0.010    B/op
   FormatBenchmarks.stringFormat:·gc.churn.G1_Eden_Space           avgt    5  1314.251 ± 139.660  MB/sec
   FormatBenchmarks.stringFormat:·gc.churn.G1_Eden_Space.norm      avgt    5  1402.548 ± 134.966    B/op
   FormatBenchmarks.stringFormat:·gc.churn.G1_Survivor_Space       avgt    5     0.007 ±   0.003  MB/sec
   FormatBenchmarks.stringFormat:·gc.churn.G1_Survivor_Space.norm  avgt    5     0.007 ±   0.003    B/op
   FormatBenchmarks.stringFormat:·gc.count                         avgt    5    81.000            counts
   FormatBenchmarks.stringFormat:·gc.time                          avgt    5    60.000                ms
   FormatBenchmarks.zeroPad                                        avgt    5    42.288 ±   1.965   ns/op
   FormatBenchmarks.zeroPad:·gc.alloc.rate                         avgt    5  1701.090 ±  79.519  MB/sec
   FormatBenchmarks.zeroPad:·gc.alloc.rate.norm                    avgt    5    88.006 ±   0.001    B/op
   FormatBenchmarks.zeroPad:·gc.churn.G1_Eden_Space                avgt    5  1709.814 ± 171.192  MB/sec
   FormatBenchmarks.zeroPad:·gc.churn.G1_Eden_Space.norm           avgt    5    88.468 ±   9.798    B/op
   FormatBenchmarks.zeroPad:·gc.churn.G1_Survivor_Space            avgt    5     0.009 ±   0.005  MB/sec
   FormatBenchmarks.zeroPad:·gc.churn.G1_Survivor_Space.norm       avgt    5    ≈ 10⁻³              B/op
   FormatBenchmarks.zeroPad:·gc.count                              avgt    5    86.000            counts
   FormatBenchmarks.zeroPad:·gc.time                               avgt    5    73.000                ms
   ```




-- 
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: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org