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

Optimize FixedArray8<T> indexer #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Oct 20, 2020

  • Use Unsafe.Add for direct access
  • Apply MethodImplOptions.AggressiveInlining
  • Use throw helper

Benchmark using AddRange

  1. Baseline
  2. Switch to Unsafe.Add in indexer
  3. Add AggressiveInlining and throw helper
Method Count Mean Error StdDev Ratio RatioSD Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
ImmutableList 10 734.9 ns 393.880 ns 21.5899 ns 1.00 0.00 1.0605 - - 834 B
ImmutableArray 10 308.4 ns 220.845 ns 12.1052 ns 0.42 0.02 0.3772 - - 297 B
ImmutableTreeList 0 10 429.7 ns 148.300 ns 8.1290 ns 0.60 0.02 0.5097 - - 401 B
ImmutableTreeList 1 10 288.7 ns 4.789 ns 0.2625 ns 0.39 0.01 0.5097 - - 401 B
ImmutableTreeList 2 10 264.2 ns 14.590 ns 0.7998 ns 0.37 0.01 0.5097 - - 401 B
ImmutableList 1000 32,815.0 ns 39,520.030 ns 2,166.2262 ns 1.00 0.00 52.0630 8.6670 - 60777 B
ImmutableArray 1000 6,758.1 ns 309.823 ns 16.9824 ns 0.21 0.01 15.8691 - - 12508 B
ImmutableTreeList 0 1000 58,769.1 ns 11,984.860 ns 656.9300 ns 1.83 0.10 14.8926 - - 11724 B
ImmutableTreeList 1 1000 38,737.7 ns 11,470.392 ns 628.7309 ns 1.18 0.06 14.8926 - - 11724 B
ImmutableTreeList 2 1000 33,213.6 ns 8,506.380 ns 466.2632 ns 1.02 0.07 14.8926 - - 11724 B
ImmutableList 100000 8,297,334.1 ns 1,368,147.755 ns 74,992.7951 ns 1.00 0.00 1000.0000 609.3750 390.6250 6265724 B
ImmutableArray 100000 718,363.3 ns 533,829.695 ns 29,261.0069 ns 0.09 0.00 399.4141 399.4141 399.4141 1452144 B
ImmutableTreeList 0 100000 10,210,487.3 ns 2,561,610.010 ns 140,410.4880 ns 1.21 0.08 187.5000 93.7500 - 1123347 B
ImmutableTreeList 1 100000 6,470,338.1 ns 1,207,622.535 ns 66,193.8661 ns 0.78 0.01 179.6875 85.9375 - 1123357 B
ImmutableTreeList 2 100000 5,601,348.3 ns 591,887.890 ns 32,443.3726 ns 0.63 0.06 179.6875 85.9375 - 1123357 B
ImmutableList 10000000 1,420,494,400.0 ns 188,008,648.079 ns 10,305,388.4080 ns 1.00 0.00 78000.0000 28000.0000 1000.0000 655634848 B
ImmutableArray 10000000 108,571,620.0 ns 81,204,808.000 ns 4,451,109.5398 ns 0.08 0.00 1400.0000 1400.0000 1400.0000 174226376 B
ImmutableTreeList 0 10000000 1,545,463,533.3 ns 160,400,634.270 ns 8,792,100.0120 ns 1.09 0.01 18000.0000 6000.0000 - 112176752 B
ImmutableTreeList 1 10000000 986,178,366.7 ns 336,117,471.221 ns 18,423,732.7752 ns 0.69 0.01 18000.0000 6000.0000 - 112176752 B
ImmutableTreeList 2 10000000 867,280,133.3 ns 155,179,711.470 ns 8,505,923.6161 ns 0.61 0.01 18000.0000 6000.0000 - 112176752 B

* Use `Unsafe.Add` for direct access
* Apply MethodImplOptions.AggressiveInlining
* Use throw helper
@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #102 into master will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #102   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          169       170    +1     
  Lines        20526     20506   -20     
  Branches      1614      1614           
=========================================
- Hits         20526     20506   -20     

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

1 participant