Refactor and optimize BlockedModules by Shane32 · Pull Request #530 · Shane32/QRCoder
This PR optimizes the speed and transient memory requirements required to note which modules are blocked and cannot be used by data. Previously a list of blocked areas was maintained, whereas now a bitmap of the entire QR code is maintaned. This results in much faster execution but consumes more memory. To compensate, a [ThreadStatic] reusable buffer is used to store the bitmap temporarily during QR code generation.
Requirements
This PR requires these other PRs to be merged in first, so GitHub will display a proper diff:
Before
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---|---|---|---|---|---|
| CreateQRCode | 97.11 us | 0.519 us | 0.460 us | 0.4883 | 9.3 KB |
| CreateQRCodeLong | 1,679.91 us | 16.805 us | 14.897 us | 1.9531 | 39.24 KB |
| CreateQRCodeLongest | 14,336.49 us | 35.724 us | 31.669 us | - | 88.35 KB |
After
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|---|---|---|---|---|---|
| CreateQRCode | 71.73 us | 0.851 us | 0.754 us | 0.3662 | 7.27 KB |
| CreateQRCodeLong | 1,314.42 us | 9.245 us | 8.195 us | - | 33.31 KB |
| CreateQRCodeLongest | 7,216.75 us | 29.611 us | 26.250 us | - | 79.74 KB |