optimise: fill `QRCode` with one colour by TimothyMakkison · Pull Request #626 · Shane32/QRCoder
net8.0-windows
Thanks 🙏
FYI, it may be possible to create a single path for the dark modules, issuing a single Fill call, further improving performance. Just guessing, and not sure what the performance impact would be.
Yeah, I wanted to use benchmarks to test this. I'd also like to know if it's worth filling the bitmap with the light or dark colour or how much faster gfx.Clear is vs painting a large rectangle.
IIRC there was an issue with mutating a bitmap a lot in C#, I can't remember if it was related to bmp.LockBits and unlocking. I did wonder if it would be better to write to a scale bitmap and then scale it up to the correct size Bitmap resized = new Bitmap(original,new Size(original.Width * 4,original.Height*4));
I'll experiment more in the morning
After
| Method | Mean | Error | StdDev | Allocated |
|---|---|---|---|---|
| DrawingBitmapByteQRCodeSmall | 855.7 us | 16.95 us | 32.25 us | 313 B |
| DrawingBitmapByteQRCodeMedium | 2,781.1 us | 55.02 us | 127.52 us | 316 B |
| DrawingBitmapByteQRCodeBig | 46,853.3 us | 968.01 us | 2,649.90 us | 401 B |
| DrawingBitmapByteQRCodeHuge | 325,011.8 us | 6,481.17 us | 12,793.20 us | 848 B |
Before
| Method | Mean | Error | StdDev | Allocated |
|---|---|---|---|---|
| DrawingBitmapByteQRCodeSmall | 2.411 ms | 0.0481 ms | 0.0843 ms | 316 B |
| DrawingBitmapByteQRCodeMedium | 6.795 ms | 0.1246 ms | 0.2545 ms | 320 B |
| DrawingBitmapByteQRCodeBig | 90.470 ms | 1.7894 ms | 4.0023 ms | 491 B |
| DrawingBitmapByteQRCodeHuge | 521.257 ms | 10.3711 ms | 18.9641 ms | 1384 B |
I can see why #240 was created, half a second for a large QR code is crazy 0_0, not sure why the memory usage is so low for a huge bitmap