Skip to content

IpAddressMatcher Performance #14493

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

Closed
tbohnen opened this issue Jan 25, 2024 · 1 comment · Fixed by #14498
Closed

IpAddressMatcher Performance #14493

tbohnen opened this issue Jan 25, 2024 · 1 comment · Fixed by #14498
Labels
in: web An issue in web modules (web, webmvc) status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement

Comments

@tbohnen
Copy link

tbohnen commented Jan 25, 2024

Expected Behavior

Given that the following String.format in IpAddressMatcher happens regardless of whether it's a valid ip address or not, there is a significant perfomance hit to doing the string formatting for even valid Ip Addresses.

Assert.isTrue(this.requiredAddress.getAddress().length * 8 >= this.nMaskBits, String.format("IP address %s is too short for bitmask of length %d", ipAddress, this.nMaskBits));

Current Behavior

It does the String.format regardless given that it's using Assert.isTrue

Context

Using an if statement or something equivalent like using the Assert.isTrue overloads with messageSupplier and only doing the format if needed for the exception should be sufficient but also doing the string formatter with something that doesn't use a pattern matcher should also be sufficient.

if (this.requiredAddress.getAddress().length * 8 < this.nMaskBits) 
{
  	throw new IllegalArgumentException(String.format("IP address %s is too short for bitmask of length %d", ipAddress, this.nMaskBits));
}
@tbohnen tbohnen added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jan 25, 2024
@jzheaux
Copy link
Contributor

jzheaux commented Jan 26, 2024

Thanks for reaching out, @tbohnen, I think you make a good point. Instead of the if statement, could we instead use Assert.isTrue(boolean, Supplier<String>)? And would you be able to submit a PR for the same?

@jzheaux jzheaux added in: web An issue in web modules (web, webmvc) status: ideal-for-contribution An issue that we actively are looking for someone to help us with and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 26, 2024
ahmd-nabil added a commit to ahmd-nabil/spring-security that referenced this issue Jan 26, 2024
ahmd-nabil added a commit to ahmd-nabil/spring-security that referenced this issue Jan 26, 2024
jzheaux pushed a commit that referenced this issue Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) status: ideal-for-contribution An issue that we actively are looking for someone to help us with type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants