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

Performance diagnostics: Adds static timer and caches handler name #1977

Merged
merged 8 commits into from
Nov 3, 2020

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Nov 2, 2020

Pull Request Template

Description

Reduces allocation by 3.6% (32.58 KB to 31.38 KB) and latency by 1.6% (567.2 to 557.7us)

  1. Reduces allocations by using a single static StopWatch instead of creating a new one for each DiagnosticScope.

This shows the performance results of getting latency from DateTime.UtcNow vs StopWatch vs StopWatch singleton

|                           Method |      Mean |    Error |   StdDev |   StdErr |       Min |        Q1 |    Median |        Q3 |       Max |         Op/s |  Gen 0 | Gen 1 | Gen 2 | Allocated |
|--------------------------------- |----------:|---------:|---------:|---------:|----------:|----------:|----------:|----------:|----------:|-------------:|-------:|------:|------:|----------:|
|           TimerDateTimeBenchmark | 126.48 ns | 0.974 ns | 1.427 ns | 0.265 ns | 123.96 ns | 125.31 ns | 126.55 ns | 127.93 ns | 128.65 ns |  7,906,436.0 |      - |     - |     - |         - |
|          TimerStopWatchBenchmark |  43.71 ns | 1.055 ns | 1.578 ns | 0.288 ns |  41.48 ns |  42.16 ns |  43.56 ns |  45.07 ns |  46.21 ns | 22,879,040.6 | 0.0063 |     - |     - |      40 B |
| TimerStopWatchSingletonBenchmark |  41.06 ns | 0.374 ns | 0.559 ns | 0.102 ns |  40.18 ns |  40.58 ns |  41.00 ns |  41.65 ns |  42.15 ns | 24,355,020.1 |      - |     - |     - |         - |

  1. Reduces allocations and latency by caching the handler name instead of getting it for each call.

The MockedItemBenchmark.ReadItemExists results:

|            Method |      Type |     Mean |   Error |   StdDev |  StdErr |   Median |      Min |       Q1 |       Q3 |      Max |      P80 |      P85 |      P90 |      P95 |     P100 |    Op/s | Completed Work Items | Lock Contentions | Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------ |---------- |---------:|--------:|---------:|--------:|---------:|---------:|---------:|---------:|---------:|---------:|---------:|---------:|---------:|---------:|--------:|---------------------:|-----------------:|------:|------:|------:|----------:|
|    ReadItemExists |    Stream | 557.7 us | 6.63 us | 61.43 us | 2.01 us | 531.8 us | 468.9 us | 514.3 us | 598.3 us | 779.6 us | 620.9 us | 638.5 us | 654.6 us | 675.0 us | 779.6 us | 1,793.0 |               1.0000 |                - |     - |     - |     - |  30.66 KB |
| ReadItemExistsOld |    Stream | 567.2 us | 7.19 us | 66.38 us | 2.18 us | 543.3 us | 464.3 us | 518.9 us | 621.1 us | 796.6 us | 637.4 us | 652.7 us | 667.8 us | 697.0 us | 796.6 us | 1,763.2 |               1.0000 |                - |     - |     - |     - |  32.38 KB |
|    ReadItemExists |       OfT | 574.1 us | 6.36 us | 58.74 us | 1.93 us | 552.4 us | 496.2 us | 531.4 us | 599.5 us | 784.7 us | 637.2 us | 658.3 us | 670.5 us | 690.2 us | 784.7 us | 1,742.0 |               1.0000 |                - |     - |     - |     - |  38.32 KB |
| ReadItemExistsOld |       OfT | 583.7 us | 6.74 us | 61.98 us | 2.04 us | 560.5 us | 488.7 us | 538.9 us | 617.1 us | 828.9 us | 645.4 us | 662.9 us | 683.5 us | 700.5 us | 828.9 us | 1,713.3 |               1.0000 |                - |     - |     - |     - |  38.63 KB |
|    ReadItemExists | OfTCustom | 573.0 us | 5.61 us | 51.19 us | 1.70 us | 555.1 us | 490.3 us | 538.9 us | 590.7 us | 746.5 us | 604.4 us | 623.9 us | 663.6 us | 689.4 us | 746.5 us | 1,745.3 |               1.0000 |                - |     - |     - |     - |  38.33 KB |
| ReadItemExistsOld | OfTCustom | 608.4 us | 8.14 us | 75.27 us | 2.47 us | 579.5 us | 503.3 us | 557.3 us | 647.4 us | 927.8 us | 673.9 us | 692.9 us | 726.9 us | 764.8 us | 927.8 us | 1,643.6 |               1.0000 |                - |     - |     - |     - |  39.52 KB |

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #IssueNumber

kirankumarkolli
kirankumarkolli previously approved these changes Nov 3, 2020
@j82w j82w dismissed stale reviews from kirankumarkolli and ealsur via dd1d473 November 3, 2020 12:41
@j82w j82w merged commit deb8565 into master Nov 3, 2020
@j82w j82w deleted the users/jawilley/perf/diagnostics branch November 3, 2020 15:02
@ghost
Copy link

ghost commented Dec 15, 2021

Closing due to in-activity, pease feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants