Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid String.split when parsing header to reduce some garbage generat… #160

Merged
merged 4 commits into from
Jun 5, 2020

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Jun 4, 2020

…ion.

Description of changes:

Instead of String.split, can use indexOf to reduce allocations of arrays. About 20% faster / less allocations, not huge but these things add up and as instrumentation we need to keep an eye on minimizing cycles to reduce the cost burden of the customer. I would say the readability is not significantly impaired. @shengxil feel free to copy this away.

After

Benchmark                                                      Mode     Cnt     Score    Error   Units
TraceHeaderBenchmark.parse                                   sample  437664     2.024 ±  0.209   us/op
TraceHeaderBenchmark.parse:parse·p0.00                       sample             0.498            us/op
TraceHeaderBenchmark.parse:parse·p0.50                       sample             0.800            us/op
TraceHeaderBenchmark.parse:parse·p0.90                       sample             0.934            us/op
TraceHeaderBenchmark.parse:parse·p0.95                       sample             1.170            us/op
TraceHeaderBenchmark.parse:parse·p0.99                       sample             4.496            us/op
TraceHeaderBenchmark.parse:parse·p0.999                      sample            40.021            us/op
TraceHeaderBenchmark.parse:parse·p0.9999                     sample          1761.280            us/op
TraceHeaderBenchmark.parse:parse·p1.00                       sample          3551.232            us/op
TraceHeaderBenchmark.parse:·gc.alloc.rate                    sample      15   627.784 ± 53.949  MB/sec
TraceHeaderBenchmark.parse:·gc.alloc.rate.norm               sample      15  1072.556 ±  0.061    B/op
TraceHeaderBenchmark.parse:·gc.churn.G1_Eden_Space           sample      15   631.644 ± 86.257  MB/sec
TraceHeaderBenchmark.parse:·gc.churn.G1_Eden_Space.norm      sample      15  1076.679 ± 92.875    B/op
TraceHeaderBenchmark.parse:·gc.churn.G1_Survivor_Space       sample      15     0.100 ±  0.017  MB/sec
TraceHeaderBenchmark.parse:·gc.churn.G1_Survivor_Space.norm  sample      15     0.172 ±  0.030    B/op
TraceHeaderBenchmark.parse:·gc.count                         sample      15    94.000           counts
TraceHeaderBenchmark.parse:·gc.time                          sample      15    95.000               ms

Before

Benchmark                                                      Mode     Cnt     Score     Error   Units
TraceHeaderBenchmark.parse                                   sample  372019     2.519 ±   0.257   us/op
TraceHeaderBenchmark.parse:parse·p0.00                       sample             0.609             us/op
TraceHeaderBenchmark.parse:parse·p0.50                       sample             0.939             us/op
TraceHeaderBenchmark.parse:parse·p0.90                       sample             1.102             us/op
TraceHeaderBenchmark.parse:parse·p0.95                       sample             1.552             us/op
TraceHeaderBenchmark.parse:parse·p0.99                       sample            15.680             us/op
TraceHeaderBenchmark.parse:parse·p0.999                      sample            60.283             us/op
TraceHeaderBenchmark.parse:parse·p0.9999                     sample          2006.213             us/op
TraceHeaderBenchmark.parse:parse·p1.00                       sample          3317.760             us/op
TraceHeaderBenchmark.parse:·gc.alloc.rate                    sample      15   719.021 ±  36.796  MB/sec
TraceHeaderBenchmark.parse:·gc.alloc.rate.norm               sample      15  1448.702 ±   0.038    B/op
TraceHeaderBenchmark.parse:·gc.churn.G1_Eden_Space           sample      15   726.083 ±  72.496  MB/sec
TraceHeaderBenchmark.parse:·gc.churn.G1_Eden_Space.norm      sample      15  1461.632 ± 107.197    B/op
TraceHeaderBenchmark.parse:·gc.churn.G1_Survivor_Space       sample      15     0.082 ±   0.084  MB/sec
TraceHeaderBenchmark.parse:·gc.churn.G1_Survivor_Space.norm  sample      15     0.165 ±   0.168    B/op
TraceHeaderBenchmark.parse:·gc.count                         sample      15   108.000            counts
TraceHeaderBenchmark.parse:·gc.time                          sample      15   109.000                ms

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@willarmiros willarmiros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a great speedup and simplification. Thanks!

@anuraaga anuraaga merged commit f18c002 into aws:master Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants