-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use substring instead of replaceFirst in OAuth2AuthorizationConsent #1223
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @heartape. Please see review comments.
CONTRIBUTING.adoc
Outdated
@@ -67,7 +67,7 @@ Use git rebase –interactive, git add –patch and other tools to "squash" mult | |||
|
|||
== Format commit messages | |||
|
|||
. Keep the subject line to 50 characters or less if possible. | |||
. Keep the subject line to 50 characters or fewer if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this as it's not related to the proposed replaceFirst()
change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgrandja I will submit a new PR for this section. Do you think this is a good idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of "less" is proper grammar so we will leave as-is
@@ -65,12 +65,6 @@ public Authentication convert(HttpServletRequest request) { | |||
principal = ANONYMOUS_AUTHENTICATION; | |||
} | |||
|
|||
String sessionId = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this as it's not related to the proposed replaceFirst()
change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -93,7 +93,7 @@ public Set<String> getScopes() { | |||
Set<String> authorities = new HashSet<>(); | |||
for (GrantedAuthority authority : getAuthorities()) { | |||
if (authority.getAuthority().startsWith(AUTHORITIES_SCOPE_PREFIX)) { | |||
authorities.add(authority.getAuthority().replaceFirst(AUTHORITIES_SCOPE_PREFIX, "")); | |||
authorities.add(authority.getAuthority().substring(AUTHORITIES_SCOPE_PREFIX.length())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I conducted a simple test and achieved a 40 times performance improvement.
How did you conduct the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all the testing information:
public static void main(String[] args) {
String scope = "SCOPE_";
String email = "SCOPE_email";
int count = 10000000;
long start1 = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
String s = email.replaceFirst(scope, "");
}
long end1 = System.currentTimeMillis();
System.out.println("replaceFirst : " + (end1 - start1));
long start2 = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
String s = email.substring(scope.length());
}
long end2 = System.currentTimeMillis();
System.out.println("substring : " + (end2 - start2));
System.out.println("count : " + count);
}
windows(8c16t 32G) idea
java version "17.0.3.1" 2022-04-22 LTS
Java(TM) SE Runtime Environment (build 17.0.3.1+2-LTS-6)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3.1+2-LTS-6, mixed mode, sharing)
result:
replaceFirst : 2383
substring : 69
count : 10000000
###############################################################
centos7 vm(2c 2G) command line
java version "17.0.6" 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
result:
replaceFirst : 2856
substring : 107
count : 10000000
Thanks for the update @heartape. This is now merged. |
Close #1222