akamsteeg / AtleX.HaveIBeenPwned

A fully async .NET Standard client library for the API of HaveIBeenPwned.com
https://www.nuget.org/packages/AtleX.HaveIBeenPwned/
MIT License
5 stars 0 forks source link

In RateLimitExceededException, only construct the message when it's needed #49

Closed akamsteeg closed 3 years ago

akamsteeg commented 3 years ago

In RateLimitExceededException, the exception message is created once it's thrown:

https://github.com/akamsteeg/AtleX.HaveIBeenPwned/blob/f2ba52019d9a5adfca231a529d7ab731c832d127/src/AtleX.HaveIBeenPwned/RateLimitExceededException.cs#L28-L29

Because this uses string interpolation it's somewhat expensive. But many times, this exception is handled automatically with for example Polly. A RateLimitExceededException is thrown, catched and after the timeout specified in the RetryAfter property has elapsed the request is retried. The message is rarely inspected in those cases. Running the string formatting and allocating a string that in many cases isn't used has a performance impact.