Skip to content

Add fast path for blittable variable-length sequence read#162

Open
marklam wants to merge 1 commit into
Apollo3zehn:masterfrom
marklam:vl-blittable-fastpath
Open

Add fast path for blittable variable-length sequence read#162
marklam wants to merge 1 commit into
Apollo3zehn:masterfrom
marklam:vl-blittable-fastpath

Conversation

@marklam

@marklam marklam commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
  • Introduce efficient decoding for blittable variable-length sequences in DatatypeMessage, avoiding boxing and allocations by casting global heap bytes directly to typed arrays. The fast path is used when element types are unmanaged and sizes match; otherwise, fallback to the existing logic.
  • Add a benchmark (VariableLengthSequenceRead) to measure performance improvements.

Benchmark before:


BenchmarkDotNet v0.14.0, Windows 11 (10.0.26200.8524)
13th Gen Intel Core i9-13900KS, 1 CPU, 24 logical and 24 physical cores
.NET SDK 10.0.300
  [Host]     : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2

Method Mean Error StdDev Gen0 Gen1 Allocated
ReadVariableLengthPeaks 563.2 μs 9.85 μs 9.21 μs 45.8984 18.5547 858.59 KB

Benchmark after:


BenchmarkDotNet v0.14.0, Windows 11 (10.0.26200.8524)
13th Gen Intel Core i9-13900KS, 1 CPU, 24 logical and 24 physical cores
.NET SDK 10.0.300
  [Host]     : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2

Method Mean Error StdDev Gen0 Gen1 Allocated
ReadVariableLengthPeaks 95.85 μs 1.885 μs 1.671 μs 10.6201 4.3945 195.91 KB

- Introduce efficient decoding for blittable variable-length sequences in DatatypeMessage, avoiding boxing and allocations by casting global heap bytes directly to typed arrays. The fast path is used when element types are unmanaged and sizes match; otherwise, fallback to the existing logic.
- Add a benchmark (VariableLengthSequenceRead) to measure performance improvements.

Benchmark before:
```

BenchmarkDotNet v0.14.0, Windows 11 (10.0.26200.8524)
13th Gen Intel Core i9-13900KS, 1 CPU, 24 logical and 24 physical cores
.NET SDK 10.0.300
  [Host]     : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2

```
| Method                  | Mean     | Error   | StdDev  | Gen0    | Gen1    | Allocated |
|------------------------ |---------:|--------:|--------:|--------:|--------:|----------:|
| ReadVariableLengthPeaks | 563.2 μs | 9.85 μs | 9.21 μs | 45.8984 | 18.5547 | 858.59 KB |

Benchmark after:
```

BenchmarkDotNet v0.14.0, Windows 11 (10.0.26200.8524)
13th Gen Intel Core i9-13900KS, 1 CPU, 24 logical and 24 physical cores
.NET SDK 10.0.300
  [Host]     : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.27 (8.0.2726.22922), X64 RyuJIT AVX2

```
| Method                  | Mean     | Error    | StdDev   | Gen0    | Gen1   | Allocated |
|------------------------ |---------:|---------:|---------:|--------:|-------:|----------:|
| ReadVariableLengthPeaks | 95.85 μs | 1.885 μs | 1.671 μs | 10.6201 | 4.3945 | 195.91 KB |
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.

1 participant