Skip to content
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

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

Merged
merged 3 commits into from
Jan 20, 2024

Conversation

skwasjer
Copy link
Owner

@skwasjer skwasjer commented Jan 20, 2024

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:

  • Loop unrolling throws (on generation) for non-fixed length patterns. This is not an issue atm. because no IBAN defined in SWIFT registry is currently of variable length, even though the spec accounts for it.
  • The WikipediaRegistryProvider has NOT been updated to receive the same treatment.

@skwasjer skwasjer force-pushed the feature/code_gen_unrolled_swift_pattern_match branch from 97ce201 to d0ee2bf Compare January 20, 2024 21:20
@skwasjer skwasjer changed the title Use code generation to unroll pattern match per country (SWIFT only) feat: use code generation to unroll pattern match per country (SWIFT only) Jan 20, 2024
@skwasjer skwasjer enabled auto-merge (squash) January 20, 2024 21:23
@skwasjer skwasjer force-pushed the feature/code_gen_unrolled_swift_pattern_match branch from d0ee2bf to fe18e4f Compare January 20, 2024 21:35
@skwasjer skwasjer disabled auto-merge January 20, 2024 21:38
…it. Exposing internals to TemporaryT4Assembly no longer works, as the temporary assembly has a new name each run (TemporaryT4Assembly_<guid>).
@skwasjer skwasjer force-pushed the feature/code_gen_unrolled_swift_pattern_match branch from fe18e4f to a491f31 Compare January 20, 2024 21:42
@skwasjer skwasjer force-pushed the feature/code_gen_unrolled_swift_pattern_match branch from a491f31 to eb3ebc6 Compare January 20, 2024 21:44
@skwasjer skwasjer enabled auto-merge (squash) January 20, 2024 21:44
Copy link

@skwasjer skwasjer changed the title feat: use code generation to unroll pattern match per country (SWIFT only) perf: use code generation to unroll pattern match per country (SWIFT only) Jan 20, 2024
@skwasjer skwasjer disabled auto-merge January 20, 2024 21:52
@skwasjer skwasjer enabled auto-merge (squash) January 20, 2024 21:52
@skwasjer skwasjer merged commit 7888b36 into main Jan 20, 2024
12 checks passed
@skwasjer skwasjer deleted the feature/code_gen_unrolled_swift_pattern_match branch January 20, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant