Skip to content

Replace regex with startsWith / endsWith check for LIKE pattern detection #3932

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

Conversation

Dockerel
Copy link
Contributor

@Dockerel Dockerel commented Jul 9, 2025

Replace regex %.*% with startsWith / endsWith check for LIKE pattern detection

  • Removes regex overhead and Micro-performance gain
  • Explicit intent (startsWith/endsWith) is clearer than a regex.

Previously, each call to expression.matches("%.*%") incurred regex compilation and Matcher allocation overhead. Caching the pattern with

private static final Pattern CONTAINING = Pattern.compile("%.*%");

would avoid recompilation, but switching to startsWith("%") && endsWith("%") is even more efficient and more readable, so the implementation has been changed accordingly.

Let me know if you have any concerns or suggestions for further improvement.
Thank you for your time and consideration!

Signed-off-by: Giheon Do <dgh0001@naver.com>
@Dockerel Dockerel force-pushed the optimize-like-parameter-binding-performance branch from f75fe97 to 95f0561 Compare July 9, 2025 11:55
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 9, 2025
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 9, 2025
@mp911de mp911de self-assigned this Jul 9, 2025
@mp911de mp911de added this to the 3.5.2 (2025.0.2) milestone Jul 10, 2025
@mp911de mp911de closed this in 5aba123 Jul 10, 2025
mp911de added a commit that referenced this pull request Jul 10, 2025
Refine conditional flow.

See #3932
mp911de pushed a commit that referenced this pull request Jul 10, 2025
…tion.

Signed-off-by: Giheon Do <dgh0001@naver.com>
Closes #3932
mp911de added a commit that referenced this pull request Jul 10, 2025
Refine conditional flow.

See #3932
@mp911de
Copy link
Member

mp911de commented Jul 10, 2025

Thank you for your contribution. That's merged, polished, and backported now.

@Dockerel Dockerel deleted the optimize-like-parameter-binding-performance branch July 10, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants