perf: RteGenericValidator 검증 정규식 반복 컴파일 제거 — 입력·비밀번호 검증 2~4.7배 (실측 벤치)#278
Open
EricSeokgon wants to merge 1 commit into
Open
perf: RteGenericValidator 검증 정규식 반복 컴파일 제거 — 입력·비밀번호 검증 2~4.7배 (실측 벤치)#278EricSeokgon wants to merge 1 commit into
EricSeokgon wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
문제 (재현)
ptl.mvc의RteGenericValidator는 폼 입력·비밀번호 검증에 쓰이는 유틸인데, 상수 정규식을 메서드 호출마다 다시 컴파일합니다.isHtmlTag()— 매 호출Pattern.compile("<[^<|>]*>")isMoreThan2CharTypeComb()— 매 호출 조합 검증 패턴 컴파일 (특수문자 집합~!@#$%^&*?은 고정)isMoreThan3CharTypeComb()— 동상세 패턴 모두 입력과 무관하게 상수이므로 클래스 로딩 시 1회만 컴파일하면 됩니다. (파라미터가 들어가는
isRepeatedNTimes()의 패턴은 가변이므로 이 PR 대상에서 제외했습니다.)수정
세 정규식을
private static final Pattern으로 호이스팅했습니다. 공개 API·검증 결과 변화 없음.검증
1) 동작 동일성 — 수정 전/후 로직을 나란히 두고 경계 입력 9종(한글·태그·이메일·각종 비밀번호 조합·빈문자열)에 대해 3개 메서드 전부 결과 일치(불일치 0) 확인.
2) 컴파일 — JDK 17.0.19로 수정본 컴파일 성공(BUILD OK). 변경 파일 1개(+14 −14), 공개 시그니처 불변.
3) 성능 (JDK 17.0.19, 워밍업 30만 회 후 200만 회 반복):
재현 하네스는 요청 주시면 바로 공유하겠습니다.
영향
isHtmlTag의"<[^<|>]*>"는 문자클래스 안의|가 리터럴로 제외 대상에 포함됩니다. 원저자 의도가[^<>]였을 가능성이 있으나, 이 PR은 성능만 다루므로 기존 정규식 의미를 그대로 보존했습니다.