skwasjer / IbanNet

C# .NET IBAN validator, parser, builder and generator
Apache License 2.0
119 stars 31 forks source link

perf: use code generation to unroll pattern match per country (SWIFT only) #192

Closed skwasjer closed 5 months ago

skwasjer commented 5 months ago

During validation of an IBAN, of all the IIbanValidationRules most time is spent in the IsMatchingStructureRule validator. To increase performance, we can make use of code generation to generate a custom SwiftPattern class per country in the SwiftRegistryProvider, in which the actual pattern validation is unrolled. This provides a significant performance increase as we no longer have to flow through the general purpose pattern validator, avoiding all the loops and branching.

Performance gains varies per .NET runtime and per country pattern, but goes as high as ~75% and at least ~25%.

Note:

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud