Skip to content
New issue

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

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

Already on GitHub? # to your account

Implement a faster encoding algoritm for varint #98

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

brantburnett
Copy link
Owner

In .NET 6 and later we can use intrinsics, especially on Intel, to encode the length as a varint more quickly. This isn't a huge difference given the overall cost of compression but may still be worthwhile.

BenchmarkDotNet v0.13.10, Windows 11 (10.0.22631.3880/23H2/2023Update/SunValley3) 12th Gen Intel Core i7-1270P, 1 CPU, 16 logical and 12 physical cores .NET SDK 8.0.303
[Host] : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2

Method Value Mean Error StdDev Ratio Rank
Current 0 1.385 ns 0.0176 ns 0.0164 ns 1.00 2
New 0 1.091 ns 0.0200 ns 0.0188 ns 0.79 1
Current 256 1.599 ns 0.0282 ns 0.0220 ns 1.00 2
New 256 1.340 ns 0.0104 ns 0.0081 ns 0.84 1
Current 65536 1.593 ns 0.0132 ns 0.0117 ns 1.00 2
New 65536 1.367 ns 0.0181 ns 0.0169 ns 0.86 1

In .NET 6 and later we can use intrinsics, especially on Intel, to
encode the length as a varint more quickly. This isn't a huge difference
given the overall cost of compression but may still be worthwhile.

BenchmarkDotNet v0.13.10, Windows 11 (10.0.22631.3880/23H2/2023Update/SunValley3)
12th Gen Intel Core i7-1270P, 1 CPU, 16 logical and 12 physical cores
.NET SDK 8.0.303
  [Host]     : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2

| Method  | Value | Mean     | Error     | StdDev    | Ratio | Rank |
|-------- |------ |---------:|----------:|----------:|------:|-----:|
| Current | 0     | 1.385 ns | 0.0176 ns | 0.0164 ns |  1.00 |    2 |
| New     | 0     | 1.091 ns | 0.0200 ns | 0.0188 ns |  0.79 |    1 |
|         |       |          |           |           |       |      |
| Current | 256   | 1.599 ns | 0.0282 ns | 0.0220 ns |  1.00 |    2 |
| New     | 256   | 1.340 ns | 0.0104 ns | 0.0081 ns |  0.84 |    1 |
|         |       |          |           |           |       |      |
| Current | 65536 | 1.593 ns | 0.0132 ns | 0.0117 ns |  1.00 |    2 |
| New     | 65536 | 1.367 ns | 0.0181 ns | 0.0169 ns |  0.86 |    1 |
@brantburnett brantburnett merged commit 460dced into main Jul 12, 2024
30 checks passed
@brantburnett brantburnett deleted the varint-fast-encode branch July 12, 2024 21:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant