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

Optimized Encoder.Encode() #124

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

greymistcube
Copy link
Contributor

Just squeezing out more performance. 🙄
Depending on the case, the speed gain seems to be about 20% ~ 30%.
On the memory side, the memory usage seems go down more drastically as the collection size gets bigger.

This is achieved through the following:

  • Removed value argument passing and returning values for tracking the encoder state.
  • Other than declaring temporary local variables, the global offset is tracked using a single variable using ref.

As a bonus, the code became more readable as well. Also a bug was fixed where an unused overloaded Encode() method was wrongly implemented (not sure if we still need to keep the method tho). 😗

Encode() original

Method SetSize WordSize Mean Error StdDev Gen0 Allocated
EncodeList 8 8 3.838 ms 0.6533 ms 0.3888 ms 265.6250 1.6 MB
EncodeDict 8 8 13.948 ms 1.2701 ms 0.8401 ms 453.1250 2.73 MB
EncodeNestedList 8 8 35.165 ms 6.0021 ms 3.9700 ms 1923.0769 11.65 MB
EncodeNestedDict 8 8 160.819 ms 25.9170 ms 17.1425 ms 3500.0000 21.6 MB
EncodeList 8 16 5.465 ms 0.1529 ms 0.1012 ms 789.0625 4.73 MB
EncodeDict 8 16 17.626 ms 0.6054 ms 0.3603 ms 1500.0000 8.99 MB
EncodeNestedList 8 16 45.677 ms 1.5729 ms 1.0404 ms 6090.9091 36.67 MB
EncodeNestedDict 8 16 168.689 ms 2.9600 ms 1.9579 ms 12333.3333 74.78 MB
EncodeList 16 8 7.854 ms 0.1353 ms 0.0895 ms 390.6250 2.42 MB
EncodeDict 16 8 31.121 ms 1.2161 ms 0.8044 ms 718.7500 4.33 MB
EncodeNestedList 16 8 130.883 ms 1.7192 ms 1.0231 ms 5750.0000 35.3 MB
EncodeNestedDict 16 8 521.700 ms 10.7511 ms 7.1112 ms 11000.0000 67.73 MB
EncodeList 16 16 10.420 ms 0.4796 ms 0.2854 ms 1437.5000 8.68 MB
EncodeDict 16 16 33.950 ms 1.6944 ms 1.1208 ms 2785.7143 16.84 MB
EncodeNestedList 16 16 160.629 ms 3.9966 ms 2.6435 ms 22500.0000 135.4 MB
EncodeNestedDict 16 16 581.700 ms 5.6855 ms 3.3833 ms 45000.0000 274.18 MB

Encode() optimized

Method SetSize WordSize Mean Error StdDev Gen0 Allocated
EncodeList 8 8 3.322 ms 0.5204 ms 0.3442 ms 265.6250 1.61 MB
EncodeDict 8 8 13.067 ms 1.4576 ms 0.9641 ms 453.1250 2.73 MB
EncodeNestedList 8 8 30.082 ms 2.4822 ms 1.4771 ms 1937.5000 11.65 MB
EncodeNestedDict 8 8 124.848 ms 11.0279 ms 7.2943 ms 3500.0000 21.61 MB
EncodeList 8 16 3.674 ms 0.4520 ms 0.2989 ms 382.8125 2.29 MB
EncodeDict 8 16 13.914 ms 1.5466 ms 1.0230 ms 671.8750 4.1 MB
EncodeNestedList 8 16 34.074 ms 4.8878 ms 3.2330 ms 2800.0000 17.14 MB
EncodeNestedDict 8 16 138.955 ms 11.0044 ms 7.2787 ms 5500.0000 33.28 MB
EncodeList 16 8 7.396 ms 0.7947 ms 0.5257 ms 398.4375 2.42 MB
EncodeDict 16 8 27.286 ms 1.7213 ms 1.1385 ms 718.7500 4.33 MB
EncodeNestedList 16 8 108.680 ms 4.5182 ms 2.9885 ms 5800.0000 35.3 MB
EncodeNestedDict 16 8 471.722 ms 9.6321 ms 6.3710 ms 11000.0000 67.73 MB
EncodeList 16 16 7.570 ms 0.1171 ms 0.0775 ms 632.8125 3.8 MB
EncodeDict 16 16 27.453 ms 0.9822 ms 0.6496 ms 1156.2500 7.07 MB
EncodeNestedList 16 16 114.874 ms 4.2063 ms 2.7822 ms 9400.0000 57.27 MB
EncodeNestedDict 16 16 462.164 ms 56.9407 ms 37.6628 ms 18000.0000 113.04 MB

@CLAassistant
Copy link

CLAassistant commented Dec 1, 2024

CLA assistant check
All committers have signed the CLA.

@riemannulus riemannulus merged commit 65b5d5a into planetarium:main Dec 3, 2024
4 checks passed
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