You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to 7632a0a. A caller may use IImageAllocator to amortize allocations for the decoded image buffer when decoding multiple images. However, several other transient allocations are made which create memory traffic. By reducing these transient allocations, we reduce the number of garbage collections required for a performance boost.
We achieve this via a few approaches:
- Use stackalloc to avoid allocating small arrays on the heap. As we are targeting netstandard 2.0 and not 2.1, we lack the ability to access the allocation safely via a Span. Instead, we must unsafely access the allocation via a pointer.
- Use Array.Empty to avoid allocating new, empty arrays for mipmaps.
- Use singletons for the IDecodeTarga classes, as they are stateless.
- In INTColor.ToF16, use out parameters to avoid allocating a small array.
This provides the following benchmark improvements.
----
Before
| Method | Payload | Mean | Error | StdDev | StdErr | Median | Gen0 | Allocated |
|------- |---------- |----------:|----------:|----------:|----------:|----------:|-------:|----------:|
| Pfim | 32bit.dds | 2.015 us | 0.0112 us | 0.0088 us | 0.0025 us | 2.016 us | 0.0381 | 496 B |
| Pfim | dxt1.dds | 38.347 us | 0.7373 us | 0.8491 us | 0.1899 us | 38.417 us | 2.8687 | 36480 B |
| Pfim | dxt3.dds | 43.061 us | 0.6037 us | 0.5647 us | 0.1458 us | 42.982 us | 2.8687 | 36480 B |
| Pfim | dxt5.dds | 48.005 us | 0.5501 us | 0.5146 us | 0.1329 us | 47.931 us | 2.8687 | 36520 B |
| Method | Payload | Mean | Error | StdDev | StdErr | Median | Gen0 | Allocated |
|------- |-------------- |---------:|----------:|----------:|----------:|---------:|-------:|----------:|
| Pfim | 24bit-rle.tga | 3.180 us | 0.0371 us | 0.0347 us | 0.0090 us | 3.183 us | 0.0191 | 272 B |
| Pfim | 32bit-rle.tga | 3.441 us | 0.0266 us | 0.0222 us | 0.0062 us | 3.436 us | 0.0191 | 272 B |
| Pfim | 32bit.tga | 2.012 us | 0.0107 us | 0.0100 us | 0.0026 us | 2.012 us | 0.0191 | 272 B |
----
After
| Method | Payload | Mean | Error | StdDev | StdErr | Median | Gen0 | Allocated |
|------- |---------- |----------:|----------:|----------:|----------:|----------:|-------:|----------:|
| Pfim | 32bit.dds | 2.034 us | 0.0242 us | 0.0226 us | 0.0058 us | 2.032 us | 0.0343 | 472 B |
| Pfim | dxt1.dds | 32.704 us | 0.6247 us | 0.6135 us | 0.1534 us | 32.393 us | - | 456 B |
| Pfim | dxt3.dds | 40.869 us | 0.1294 us | 0.1211 us | 0.0313 us | 40.860 us | - | 456 B |
| Pfim | dxt5.dds | 43.623 us | 0.2501 us | 0.2340 us | 0.0604 us | 43.594 us | - | 456 B |
| Method | Payload | Mean | Error | StdDev | StdErr | Median | Gen0 | Allocated |
|------- |-------------- |---------:|----------:|----------:|----------:|---------:|-------:|----------:|
| Pfim | 24bit-rle.tga | 2.965 us | 0.0502 us | 0.0469 us | 0.0121 us | 2.973 us | 0.0191 | 248 B |
| Pfim | 32bit-rle.tga | 3.332 us | 0.0531 us | 0.0443 us | 0.0123 us | 3.329 us | 0.0191 | 248 B |
| Pfim | 32bit.tga | 2.367 us | 0.0404 us | 0.0358 us | 0.0096 us | 2.358 us | 0.0191 | 248 B |
0 commit comments