Describe the bug In commit https://github.com/spring-projects/spring-security/commit/7288fecc2449b2673c817e28654de7edc6db96a5 the assertion on the input to check if the input was a valid ip was "fixed" to make it more complete, unfortunately the additional checks significantly increase CPU time which was unexpected.

It seems that the new assertions are more computationally expensive than the actual matching code.

To Reproduce Run sample below for a basic test showing the difference is performance

Expected behavior No significant performance regressions

Sample

(https://gist.github.com/Mnkras/b02bd4e68cc4455d1aed6b2dde8c411f)

@jzheaux FYI

Comment From: jzheaux

Thanks for the report, @Mnkras. I've made some performance improvements. On my machine, the ratio drops from ~500 to ~10. Can you please try the 6.3.2-SNAPSHOT and let me know?

Comment From: Mnkras

That looks like it will be way faster, for cases where you know the input will be valid, would it make sense to add a flag to skip the assertions?