FileOnQ / Imaging.Heif

A C#/.NET wrapper around libheif for decoding and processing high efficiency image formats (heif, heic).
GNU Lesser General Public License v3.0
15 stars 4 forks source link

Addressing memory leak with SetDLLDirectory. #72

Closed kenny-sellers closed 2 years ago

kenny-sellers commented 2 years ago

Fixes: #65 Fixes: #67

Description

The UpdatedllSearchPath method was causing a memory leak. The resolution for this issue was to add a property that is evaluated every time the method is called to determine if the DLL directory has been set. This resolves the memory leak for .NET 4.8 as well as .NET 6.

Before Benchmarks

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated Allocated native memory Native memory leak
Thumbnail_Write 29.09 ms 0.211 ms 0.187 ms - - - 74,504 B 5,125,345 B 234 B
Thumbnail_ToArray 28.79 ms 0.171 ms 0.160 ms - - - 74,504 B 5,124,925 B 234 B
Thumbnail_ToSpan 29.12 ms 0.258 ms 0.215 ms - - - - 5,124,909 B 234 B
Thumbnail_ToStream 29.11 ms 0.366 ms 0.343 ms - - - 140,816 B 5,124,925 B 234 B
Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated Allocated native memory Native memory leak
PrimaryImage_Write 1.342 s 0.0043 s 0.0038 s - - - 1,951,112 B 222,030,860 B 234 B
PrimaryImage_ToArray 1.343 s 0.0031 s 0.0028 s - - - 1,951,112 B 222,030,552 B 234 B
PrimaryImage_ToSpan 1.342 s 0.0057 s 0.0053 s - - - - 222,029,928 B 234 B
PrimaryImage_ToStream 1.341 s 0.0043 s 0.0038 s - - - 3,894,032 B 222,030,392 B 234 B

After Benchmarks

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated Allocated native memory Native memory leak
Thumbnail_Write 29.09 ms 0.211 ms 0.187 ms - - - 74,504 B 5,125,345 B -
Thumbnail_ToArray 28.79 ms 0.171 ms 0.160 ms - - - 74,504 B 5,124,925 B -
Thumbnail_ToSpan 29.12 ms 0.258 ms 0.215 ms - - - - 5,124,909 B -
Thumbnail_ToStream 29.11 ms 0.366 ms 0.343 ms - - - 140,816 B 5,124,925 B -
Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated Allocated native memory Native memory leak
PrimaryImage_Write 1.342 s 0.0043 s 0.0038 s - - - 1,951,112 B 222,030,860 B -
PrimaryImage_ToArray 1.343 s 0.0031 s 0.0028 s - - - 1,951,112 B 222,030,552 B -
PrimaryImage_ToSpan 1.342 s 0.0057 s 0.0053 s - - - - 222,029,928 B -
PrimaryImage_ToStream 1.341 s 0.0043 s 0.0038 s - - - 3,894,032 B 222,030,392 B -

Merge Checklist

SkyeHoefling commented 2 years ago

@kenny-sellers can you try using a static constructor instead of this technique. You would move all of this code to a static constructor, then we wouldn't need to reference it from the HeifImage

SkyeHoefling commented 2 years ago

This looks good to me, but I am going to try moving the static constructor to HeifImage. I think it makes more sense in the entry point of the shared code instead of the native code. I'll push an update in a little bit. My update will also include the latest merge from main

SkyeHoefling commented 2 years ago

My local benchmark results show no memory leaks

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1415 (21H1/May2021Update)
AMD Ryzen 9 3950X, 1 CPU, 32 logical and 16 physical cores
  [Host]     : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT
  Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT

Runtime=.NET Framework 4.8  InvocationCount=1  LaunchCount=1
UnrollFactor=1

|             Method |     Mean |    Error |   StdDev | Allocated native memory | Native memory leak | Allocated |
|------------------- |---------:|---------:|---------:|------------------------:|-------------------:|----------:|
|    Thumbnail_Write | 33.68 ms | 0.278 ms | 0.260 ms |             5,123,833 B |                  - |  74,504 B |
|  Thumbnail_ToArray | 33.63 ms | 0.322 ms | 0.301 ms |             5,123,277 B |                  - |  74,504 B |
|   Thumbnail_ToSpan | 33.47 ms | 0.261 ms | 0.218 ms |             5,123,533 B |                  - |         - |
| Thumbnail_ToStream | 33.71 ms | 0.576 ms | 0.539 ms |             5,123,277 B |                  - | 140,816 B |
kenny-sellers commented 2 years ago

@ahoefling here are benchmarks for all frameworks

.Net 6 Thumbnail


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1466 (21H1/May2021Update)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=6.0.101
  [Host]     : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
  Job-VPNBQD : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT

Runtime=.NET 6.0  InvocationCount=1  LaunchCount=1  
UnrollFactor=1  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
Thumbnail_Write 28.72 ms 0.261 ms 0.244 ms 5,124,333 B - 832 B
Thumbnail_ToArray 29.86 ms 0.411 ms 0.385 ms 5,123,801 B - 66,888 B
Thumbnail_ToSpan 28.75 ms 0.336 ms 0.280 ms 5,123,801 B - 600 B
Thumbnail_ToStream 28.62 ms 0.202 ms 0.158 ms 5,123,801 B - 66,952 B

.Net 5 Thumbnail


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1466 (21H1/May2021Update)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=6.0.101
  [Host]     : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
  Job-QLUVLW : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT

Runtime=.NET 5.0  InvocationCount=1  LaunchCount=1  
UnrollFactor=1  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
Thumbnail_Write 28.79 ms 0.237 ms 0.211 ms 5,124,365 B - 288 B
Thumbnail_ToArray 28.82 ms 0.276 ms 0.244 ms 5,123,813 B - 66,408 B
Thumbnail_ToSpan 28.51 ms 0.297 ms 0.248 ms 5,123,817 B - 120 B
Thumbnail_ToStream 28.90 ms 0.400 ms 0.374 ms 5,123,801 B - 66,472 B

.Net 4.8 Thumbnail


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1466 (21H1/May2021Update)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
  [Host]     : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT
  Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT

Runtime=.NET Framework 4.8  InvocationCount=1  LaunchCount=1  
UnrollFactor=1  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
Thumbnail_Write 28.93 ms 0.369 ms 0.327 ms 5,123,831 B - 74,504 B
Thumbnail_ToArray 28.88 ms 0.337 ms 0.316 ms 5,123,543 B - 74,504 B
Thumbnail_ToSpan 28.84 ms 0.414 ms 0.387 ms 5,123,543 B - -
Thumbnail_ToStream 29.05 ms 0.271 ms 0.254 ms 5,123,543 B - 140,816 B

.Net 6 Primary


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1466 (21H1/May2021Update)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=6.0.101
  [Host]     : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
  Job-RHOQLY : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT

Runtime=.NET 6.0  InvocationCount=1  LaunchCount=1  
UnrollFactor=1  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
PrimaryImage_Write 1.307 s 0.0053 s 0.0050 s 222,029,704 B - 848 B
PrimaryImage_ToArray 1.304 s 0.0040 s 0.0035 s 222,028,932 B - 1,943,536 B
PrimaryImage_ToSpan 1.312 s 0.0047 s 0.0044 s 222,029,188 B - 616 B
PrimaryImage_ToStream 1.315 s 0.0080 s 0.0075 s 222,029,140 B - 1,943,600 B

.Net 5 Primary


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1466 (21H1/May2021Update)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=6.0.101
  [Host]     : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
  Job-TWRSHQ : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT

Runtime=.NET 5.0  InvocationCount=1  LaunchCount=1  
UnrollFactor=1  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
PrimaryImage_Write 1.305 s 0.0021 s 0.0020 s 222,029,608 B - 256 B
PrimaryImage_ToArray 1.306 s 0.0044 s 0.0041 s 222,029,028 B - 1,943,008 B
PrimaryImage_ToSpan 1.306 s 0.0031 s 0.0029 s 222,029,012 B - 88 B
PrimaryImage_ToStream 1.308 s 0.0036 s 0.0034 s 222,029,172 B - 1,943,072 B

.NET 4.8 Primary


BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1466 (21H1/May2021Update)
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
  [Host]     : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT
  Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT

Runtime=.NET Framework 4.8  InvocationCount=1  LaunchCount=1  
UnrollFactor=1  
Method Mean Error StdDev Allocated native memory Native memory leak Allocated
PrimaryImage_Write 1.312 s 0.0054 s 0.0051 s 222,029,490 B - 1,951,112 B
PrimaryImage_ToArray 1.304 s 0.0028 s 0.0025 s 222,029,186 B - 1,951,112 B
PrimaryImage_ToSpan 1.306 s 0.0037 s 0.0033 s 222,028,994 B - -
PrimaryImage_ToStream 1.310 s 0.0032 s 0.0028 s 222,029,250 B - 3,894,032 B
SkyeHoefling commented 2 years ago

Thanks @kenny-sellers for the updated benchmarks. I just got the automated benchmarks working. I am going to run them on this PR and if everything checks out we will merge

SkyeHoefling commented 2 years ago

/benchmark

github-actions[bot] commented 2 years ago

Benchmark Comparison - .NET Framework 4.8

Benchmarking comparison between this Pull Request and the comitted values at benchmarks/results

thumbnail

 No differences found between the benchmark results with threshold 10%.

primary

 summary:
worse: 4, geomean: 1.406
total diff: 4

| Slower                                                             | diff/base | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------------ | ---------:| ----------------:| ----------------:| --------:|
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToSpan   |      1.45 |    2161784100.00 |    3136505200.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_Write    |      1.43 |    2134797200.00 |    3057639700.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToArray  |      1.41 |    2142945150.00 |    3027376400.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToStream |      1.33 |    2279356050.00 |    3037570450.00 |         |

No Faster results for the provided threshold = 10% and noise filter = 0.3ns.

No file given

Benchmark Results - .NET Framework 4.8

thumbnail

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5), VM=Hyper-V Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores [Host] : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Runtime=.NET Framework 4.8 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |------------------- |---------:|---------:|---------:|------------------------:|-------------------:|----------:| | Thumbnail_Write | 60.05 ms | 1.162 ms | 0.971 ms | 5,123,891 B | - | 74,504 B | | Thumbnail_ToArray | 58.56 ms | 0.644 ms | 0.503 ms | 5,123,579 B | - | 74,504 B | | Thumbnail_ToSpan | 59.97 ms | 1.191 ms | 1.463 ms | 5,123,563 B | - | - | | Thumbnail_ToStream | 58.97 ms | 1.014 ms | 0.996 ms | 5,123,563 B | - | 140,816 B |

primary

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5), VM=Hyper-V Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores [Host] : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Runtime=.NET Framework 4.8 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |---------------------- |--------:|---------:|---------:|------------------------:|-------------------:|------------:| | PrimaryImage_Write | 3.044 s | 0.0602 s | 0.0618 s | 222,028,926 B | - | 1,951,112 B | | PrimaryImage_ToArray | 3.030 s | 0.0603 s | 0.0619 s | 222,028,726 B | - | 1,951,112 B | | PrimaryImage_ToSpan | 3.127 s | 0.0588 s | 0.0630 s | 222,028,694 B | - | - | | PrimaryImage_ToStream | 3.041 s | 0.0346 s | 0.0307 s | 222,028,630 B | - | 3,894,032 B |

Benchmark Comparison - .NET 5

Benchmarking comparison between this Pull Request and the comitted values at benchmarks/results

thumbnail

 summary:
better: 4, geomean: 1.199
total diff: 4

No Slower results for the provided threshold = 10% and noise filter = 0.3ns.

| Faster                                                       | base/diff | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------ | ---------:| ----------------:| ----------------:| --------:|
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_ToStream |      1.21 |      57181600.00 |      47295400.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_Write    |      1.21 |      57814850.00 |      47877400.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_ToArray  |      1.19 |      56838000.00 |      47636800.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_ToSpan   |      1.18 |      56244450.00 |      47469500.00 |         |

No file given

primary

 No differences found between the benchmark results with threshold 10%.

Benchmark Results - .NET 5

thumbnail

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8272CL CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Job-ARKDNI : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Runtime=.NET 5.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |------------------- |---------:|---------:|---------:|------------------------:|-------------------:|----------:| | Thumbnail_Write | 47.86 ms | 0.349 ms | 0.327 ms | 5,124,409 B | - | 288 B | | Thumbnail_ToArray | 47.58 ms | 0.419 ms | 0.392 ms | 5,123,853 B | - | 66,408 B | | Thumbnail_ToSpan | 47.33 ms | 0.490 ms | 0.459 ms | 5,123,885 B | 32 B | 120 B | | Thumbnail_ToStream | 47.34 ms | 0.463 ms | 0.433 ms | 5,123,853 B | - | 66,472 B |

primary

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8272CL CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Job-IYSJHZ : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Runtime=.NET 5.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |---------------------- |--------:|---------:|---------:|------------------------:|-------------------:|------------:| | PrimaryImage_Write | 2.382 s | 0.0056 s | 0.0049 s | 222,029,492 B | - | 256 B | | PrimaryImage_ToArray | 2.418 s | 0.0039 s | 0.0035 s | 222,028,744 B | - | 1,943,008 B | | PrimaryImage_ToSpan | 2.434 s | 0.0037 s | 0.0031 s | 222,028,808 B | - | 88 B | | PrimaryImage_ToStream | 2.434 s | 0.0066 s | 0.0062 s | 222,028,968 B | - | 1,943,072 B |

Benchmark Comparison - .NET 6

Benchmarking comparison between this Pull Request and the comitted values at benchmarks/results

thumbnail

 summary:
worse: 4, geomean: 1.222
total diff: 4

| Slower                                                       | diff/base | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------ | ---------:| ----------------:| ----------------:| -------- |
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_ToSpan   |      1.25 |      46290500.00 |      57854050.00 | several?|
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_Write    |      1.22 |      47674300.00 |      58042350.00 | several?|
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_ToArray  |      1.21 |      47548400.00 |      57658950.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.Thumbnail.Thumbnail_ToStream |      1.21 |      46439900.00 |      56172700.00 | several?|

No Faster results for the provided threshold = 10% and noise filter = 0.3ns.

No file given

primary

 summary:
worse: 4, geomean: 1.175
total diff: 4

| Slower                                                             | diff/base | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------------ | ---------:| ----------------:| ----------------:| --------:|
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToArray  |      1.20 |    2527876600.00 |    3038504300.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToSpan   |      1.17 |    2608975100.00 |    3058000500.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToStream |      1.17 |    2594352950.00 |    3028373100.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_Write    |      1.16 |    2603802500.00 |    3014373700.00 |         |

No Faster results for the provided threshold = 10% and noise filter = 0.3ns.

No file given

Benchmark Results - .NET 6

thumbnail

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Job-IAJLLP : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Runtime=.NET 6.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |------------------- |---------:|---------:|---------:|------------------------:|-------------------:|----------:| | Thumbnail_Write | 58.10 ms | 0.945 ms | 0.738 ms | 5,124,425 B | - | 832 B | | Thumbnail_ToArray | 57.52 ms | 1.131 ms | 1.585 ms | 5,123,853 B | - | 66,888 B | | Thumbnail_ToSpan | 57.69 ms | 1.129 ms | 1.001 ms | 5,123,853 B | - | 600 B | | Thumbnail_ToStream | 56.52 ms | 1.102 ms | 1.683 ms | 5,123,853 B | - | 66,952 B |

primary

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Job-QEQOMI : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Runtime=.NET 6.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |---------------------- |--------:|---------:|---------:|------------------------:|-------------------:|------------:| | PrimaryImage_Write | 3.011 s | 0.0208 s | 0.0194 s | 222,029,076 B | - | 848 B | | PrimaryImage_ToArray | 3.039 s | 0.0306 s | 0.0286 s | 222,028,792 B | - | 1,943,536 B | | PrimaryImage_ToSpan | 3.056 s | 0.0265 s | 0.0234 s | 222,028,728 B | - | 616 B | | PrimaryImage_ToStream | 3.033 s | 0.0144 s | 0.0135 s | 222,028,664 B | - | 1,943,552 B |

SkyeHoefling commented 2 years ago

Looks like thumbnail ToSpan leaked. I'm going to rerun the benchmark

SkyeHoefling commented 2 years ago

/benchmark

github-actions[bot] commented 2 years ago

Benchmark Comparison - .NET Framework 4.8

Benchmarking comparison between this Pull Request and the comitted values at benchmarks/results

thumbnail

 No differences found between the benchmark results with threshold 10%.

primary

 summary:
worse: 4, geomean: 1.298
total diff: 4

| Slower                                                             | diff/base | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------------ | ---------:| ----------------:| ----------------:| --------:|
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_Write    |      1.40 |    2134797200.00 |    2982269900.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToSpan   |      1.31 |    2161784100.00 |    2829898300.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToArray  |      1.28 |    2142945150.00 |    2743673900.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToStream |      1.21 |    2279356050.00 |    2766976750.00 |         |

No Faster results for the provided threshold = 10% and noise filter = 0.3ns.

No file given

Benchmark Results - .NET Framework 4.8

thumbnail

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5), VM=Hyper-V Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores [Host] : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Runtime=.NET Framework 4.8 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Median | Allocated native memory | Native memory leak | Allocated | |------------------- |---------:|---------:|---------:|---------:|------------------------:|-------------------:|----------:| | Thumbnail_Write | 59.36 ms | 1.167 ms | 1.091 ms | 59.51 ms | 5,123,891 B | - | 74,504 B | | Thumbnail_ToArray | 59.17 ms | 1.157 ms | 2.364 ms | 58.64 ms | 5,123,307 B | - | 74,504 B | | Thumbnail_ToSpan | 59.17 ms | 1.047 ms | 1.779 ms | 58.91 ms | 5,123,579 B | - | - | | Thumbnail_ToStream | 60.52 ms | 1.209 ms | 2.851 ms | 59.45 ms | 5,123,563 B | - | 140,816 B |

primary

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5), VM=Hyper-V Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores [Host] : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Job-GHSIOX : .NET Framework 4.8 (4.8.4420.0), X64 RyuJIT Runtime=.NET Framework 4.8 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |---------------------- |--------:|---------:|---------:|------------------------:|-------------------:|------------:| | PrimaryImage_Write | 2.989 s | 0.0554 s | 0.0518 s | 222,028,750 B | - | 1,951,112 B | | PrimaryImage_ToArray | 2.767 s | 0.0547 s | 0.0671 s | 222,028,966 B | - | 1,951,112 B | | PrimaryImage_ToSpan | 2.828 s | 0.0560 s | 0.1118 s | 222,028,774 B | - | - | | PrimaryImage_ToStream | 2.774 s | 0.0483 s | 0.0517 s | 222,029,014 B | - | 3,894,032 B |

Benchmark Comparison - .NET 5

Benchmarking comparison between this Pull Request and the comitted values at benchmarks/results

thumbnail

 No differences found between the benchmark results with threshold 10%.

primary

 summary:
worse: 4, geomean: 1.269
total diff: 4

| Slower                                                             | diff/base | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------------ | ---------:| ----------------:| ----------------:| -------- |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToStream |      1.27 |    2339201050.00 |    2982379850.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_Write    |      1.27 |    2279230100.00 |    2905592400.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToSpan   |      1.27 |    2335230900.00 |    2976810300.00 | bimodal |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToArray  |      1.25 |    2330930750.00 |    2920373000.00 |         |

No Faster results for the provided threshold = 10% and noise filter = 0.3ns.

No file given

Benchmark Results - .NET 5

thumbnail

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Job-AGFPST : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Runtime=.NET 5.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |------------------- |---------:|---------:|---------:|------------------------:|-------------------:|----------:| | Thumbnail_Write | 59.29 ms | 1.184 ms | 1.912 ms | 5,124,425 B | - | 288 B | | Thumbnail_ToArray | 58.66 ms | 1.163 ms | 1.339 ms | 5,123,869 B | - | 66,408 B | | Thumbnail_ToSpan | 58.68 ms | 1.150 ms | 1.889 ms | 5,123,597 B | - | 120 B | | Thumbnail_ToStream | 57.98 ms | 1.150 ms | 1.370 ms | 5,123,853 B | - | 66,472 B |

primary

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Job-SNCXBV : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT Runtime=.NET 5.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |---------------------- |--------:|---------:|---------:|------------------------:|-------------------:|------------:| | PrimaryImage_Write | 2.906 s | 0.0174 s | 0.0145 s | 222,029,380 B | - | 256 B | | PrimaryImage_ToArray | 2.928 s | 0.0267 s | 0.0250 s | 222,028,824 B | - | 1,943,056 B | | PrimaryImage_ToSpan | 2.981 s | 0.0252 s | 0.0236 s | 222,028,216 B | - | 88 B | | PrimaryImage_ToStream | 2.977 s | 0.0276 s | 0.0245 s | 222,028,888 B | - | 1,943,120 B |

Benchmark Comparison - .NET 6

Benchmarking comparison between this Pull Request and the comitted values at benchmarks/results

thumbnail

 No differences found between the benchmark results with threshold 10%.

primary

 summary:
worse: 3, geomean: 1.144
total diff: 3

| Slower                                                             | diff/base | Base Median (ns) | Diff Median (ns) | Modality|
| ------------------------------------------------------------------ | ---------:| ----------------:| ----------------:| --------:|
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToStream |      1.15 |    2594352950.00 |    2979033400.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToArray  |      1.14 |    2527876600.00 |    2893204600.00 |         |
| FileOnQ.Imaging.Heif.Benchmarks.PrimaryImage.PrimaryImage_ToSpan   |      1.14 |    2608975100.00 |    2975119200.00 |         |

No Faster results for the provided threshold = 10% and noise filter = 0.3ns.

No file given

Benchmark Results - .NET 6

thumbnail

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8272CL CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Job-EELGXR : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Runtime=.NET 6.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |------------------- |---------:|---------:|---------:|------------------------:|-------------------:|----------:| | Thumbnail_Write | 48.18 ms | 0.541 ms | 0.506 ms | 5,124,409 B | - | 832 B | | Thumbnail_ToArray | 47.45 ms | 0.539 ms | 0.504 ms | 5,123,597 B | - | 66,888 B | | Thumbnail_ToSpan | 47.54 ms | 0.425 ms | 0.398 ms | 5,123,853 B | - | 600 B | | Thumbnail_ToStream | 47.74 ms | 0.457 ms | 0.427 ms | 5,123,853 B | - | 66,952 B |

primary

``` ini BenchmarkDotNet=v0.13.1, OS=Windows 10.0.17763.2366 (1809/October2018Update/Redstone5) Intel Xeon Platinum 8171M CPU 2.60GHz, 1 CPU, 2 logical and 2 physical cores .NET SDK=6.0.101 [Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Job-AMEHTW : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT Runtime=.NET 6.0 InvocationCount=1 LaunchCount=1 UnrollFactor=1 ``` | Method | Mean | Error | StdDev | Allocated native memory | Native memory leak | Allocated | |---------------------- |--------:|---------:|---------:|------------------------:|-------------------:|------------:| | PrimaryImage_Write | 2.869 s | 0.0189 s | 0.0167 s | 222,029,556 B | - | 848 B | | PrimaryImage_ToArray | 2.887 s | 0.0384 s | 0.0340 s | 222,028,872 B | - | 1,943,536 B | | PrimaryImage_ToSpan | 2.968 s | 0.0271 s | 0.0241 s | 222,029,080 B | - | 616 B | | PrimaryImage_ToStream | 2.978 s | 0.0368 s | 0.0344 s | 222,028,952 B | - | 1,943,600 B |

SkyeHoefling commented 2 years ago

The 2nd benchmark ran successfully. I think we may have an issue with the ToSpan API in .NET 5 and .NET 6 as the 1st benchmark showed a memory leak. Both the .NET 5 and .NET 6 benchmark document native memory allocations that I don't expect. Our ToSpan implementation uses native pointers and wraps those so there shouldn't be any additional bytes allocated. This goes well outside the scope of this PR and it is something we need to research and determine if we need to make a code change. I have created #75 to track this work.

Last thing we need to do prior to merging is upload the last benchmark results. I'll take care of this and then we can merge