-
Notifications
You must be signed in to change notification settings - Fork 4
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
Addressing memory leak with SetDLLDirectory. #72
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kenny-sellers for the contribution. This looks good to me, I'm going to ask around to other library authors and see if there is a better way to do one-time start up code and what consequences this change might have.
@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 |
This looks good to me, but I am going to try moving the static constructor to |
My local benchmark results show no memory leaks
|
@ahoefling here are benchmarks for all frameworks .Net 6 ThumbnailBenchmarkDotNet=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
.Net 5 ThumbnailBenchmarkDotNet=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
.Net 4.8 ThumbnailBenchmarkDotNet=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
.Net 6 PrimaryBenchmarkDotNet=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
.Net 5 PrimaryBenchmarkDotNet=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
.NET 4.8 PrimaryBenchmarkDotNet=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
|
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 |
/benchmark |
Benchmark Comparison - .NET Framework 4.8Benchmarking 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.8thumbnail
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
primary
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
Benchmark Comparison - .NET 5Benchmarking 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 5thumbnail
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
primary
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
Benchmark Comparison - .NET 6Benchmarking 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 6thumbnail
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
primary
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
|
Looks like thumbnail ToSpan leaked. I'm going to rerun the benchmark |
/benchmark |
Benchmark Comparison - .NET Framework 4.8Benchmarking 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.8thumbnail
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
primary
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
Benchmark Comparison - .NET 5Benchmarking 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 5thumbnail
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
primary
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
Benchmark Comparison - .NET 6Benchmarking 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 6thumbnail
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
primary
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
|
The 2nd benchmark ran successfully. I think we may have an issue with the 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 |
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
After Benchmarks
Merge Checklist