PictureBox with stretched image in .Net 8 is 10 times slower than in .Net Framework
.NET version
8
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
Drawing of PictureBox with stretched image in .Net 8 is 10 times slower than in .Net Framework. This slowdown is noticeable when form and PictureBox is resized by dragging border of the form with mouse.
Steps to reproduce
I have a simple form with a PictureBox that is larger than the image assigned to it and with SizeMode set to PictureBoxSizeMode.StretchImage.
Im using this code to test drawing performance of this form.
Stopwatch sw = new Stopwatch();
long ts = 0;
long ct = 1000;
sw.Restart();
for (int i = 0; i < ct; i++)
{
Refresh();
}
sw.Stop();
ts += sw.ElapsedMilliseconds;
decimal m = 1M * ts / ct;
var msg = $"count:{ct} time(milliseconds):{ts} average:{m:0.000}";
MessageBox.Show(msg);
In .Net it takes 10 times more time to do this than in .Net Framework.
@JeremyKuhne - could this be System.Drawing related?
@LeafShi1 - please investigate if you can find where a regression may have occurred. Perhaps test with .NET 6, 8, and 9.
could this be System.Drawing related?
@merriemcgaw Possibly, although I'd be more suspicious of other layout impacting changes. @LeafShi1 also worth comparing performance in .NET 10.
I have noticed that this slowdown happens in x64 build, in x86 build Picturebox is 5 to 6 times faster.
-
AnyCPU Behavior Differs Between Frameworks
- In .NET Framework, AnyCPU typically defaults to x86 when “Prefer 32-bit” is enabled.
- In .NET Core / .NET 5+, AnyCPU defaults to x64 because the host process is 64-bit.
- Therefore, performance results under AnyCPU are not directly comparable across these frameworks.
-
x64 Performance Trend
- Starting from .NET 5.0, x64 performance becomes stable, averaging around 10 ms.
- Compared to .NET Framework x64 (≈42 ms), this is a significant improvement.
-
x86 Performance Trend
- On .NET 5.0, x86 performance is noticeably worse (≈10.7 ms) than .NET Framework (≈4.5 ms).
- Later versions show gradual improvement, but still remain slower than .NET Framework.
This difference occurs between .NET Core 3.1 and .NET 5.0.
For a maximized form (FullHD) with a docked PictureBox inside it im getting these numbers:
- application built for X86 - 11ms;
- application built for X64 - 71ms;
It's true that larger images take longer, but the difference between x86 and x64 isn't as significant as six or seven times.
.NET 10.0 project, maximized form with a docked PictureBox
On 2560x1600 screen:
- x86 - 24ms
- x64 - 38ms
On 3840x2160 screen:
- x86 - 51ms
- x64 - 77ms
I did the testing for .Net 8 on 2 PC - Win10 and Win11 (and on VM Win10) and in all cases i saw the performance 7 times lower on x64 build.
Another thing worries me: why is x64 so much slower than x86 everywhere?