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

Field wrapper optimizations #2056

Merged
merged 4 commits into from
Dec 24, 2023
Merged

Conversation

kyri-petrou
Copy link
Collaborator

In this PR, we focus mostly on improving performance of field wrappers (specifically, of tracing wrappers). These wrappers are executed for each effectfull field (or for all fields), so even the smallest improvement can have an impact on performance.

The main changes are that we use AtomicReference in-favour of Ref (which is what zio's Ref uses under the hood), and the unsafe variant of ZIO's clock. This allows us to skip a few .flatMaps when wrapping fields as we can "unsafely" get the current nano time and write to the AtomicReference.

I also disabled tracing for Wrappers and Schemas that we provide. This doesn't affect performance but it'll make debugging for users easier as they won't be seeing a lot of traces resulting from our code

series 2.x:

[info] Benchmark                                                         Mode  Cnt         Score      Error   Units
[info] NestedZQueryBenchmark.apolloTracingBenchmark                     thrpt    5       190.541 ±    3.949   ops/s
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.alloc.rate       thrpt    5      6643.802 ±  137.479  MB/sec
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.alloc.rate.norm  thrpt    5  36563555.526 ±  797.036    B/op
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.count            thrpt    5       125.000             counts
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.time             thrpt    5       298.000                 ms
[info] NestedZQueryBenchmark.metricsBenchmark                           thrpt    5       460.035 ±    9.852   ops/s
[info] NestedZQueryBenchmark.metricsBenchmark:gc.alloc.rate             thrpt    5      8324.785 ±  177.717  MB/sec
[info] NestedZQueryBenchmark.metricsBenchmark:gc.alloc.rate.norm        thrpt    5  18975774.012 ± 2315.991    B/op
[info] NestedZQueryBenchmark.metricsBenchmark:gc.count                  thrpt    5        95.000             counts
[info] NestedZQueryBenchmark.metricsBenchmark:gc.time                   thrpt    5       419.000                 ms

PR:

[info] Benchmark                                                         Mode  Cnt         Score      Error   Units
[info] NestedZQueryBenchmark.apolloTracingBenchmark                     thrpt    5       298.499 ±   15.639   ops/s
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.alloc.rate       thrpt    5      7047.581 ±  368.964  MB/sec
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.alloc.rate.norm  thrpt    5  24758162.212 ± 2569.026    B/op
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.count            thrpt    5       145.000             counts
[info] NestedZQueryBenchmark.apolloTracingBenchmark:gc.time             thrpt    5       285.000                 ms
[info] NestedZQueryBenchmark.metricsBenchmark                           thrpt    5       636.859 ±   21.087   ops/s
[info] NestedZQueryBenchmark.metricsBenchmark:gc.alloc.rate             thrpt    5      9361.317 ±  309.111  MB/sec
[info] NestedZQueryBenchmark.metricsBenchmark:gc.alloc.rate.norm        thrpt    5  15413909.358 ± 1921.828    B/op
[info] NestedZQueryBenchmark.metricsBenchmark:gc.count                  thrpt    5        87.000             counts
[info] NestedZQueryBenchmark.metricsBenchmark:gc.time                   thrpt    5       478.000                 ms

@kyri-petrou kyri-petrou merged commit 01dba86 into series/2.x Dec 24, 2023
10 checks passed
@kyri-petrou kyri-petrou deleted the field-wrapper-improvements branch December 24, 2023 04:27
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.

3 participants