Skip to content

Remove internal Optional usage in favor of null checks #7155

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
rwinch opened this issue Jul 26, 2019 · 3 comments · Fixed by #7295
Closed

Remove internal Optional usage in favor of null checks #7155

rwinch opened this issue Jul 26, 2019 · 3 comments · Fixed by #7295
Assignees
Labels
type: task A general task
Milestone

Comments

@rwinch
Copy link
Member

rwinch commented Jul 26, 2019

Summary

While some prefer the readability of using the Optional API, the GC overhead of creating additional objects (including intermediate objects) can cause significant decrease in performance There are some simple benchmarks that illustrate the problem.

We should replace Optional usage with null checks throughout Spring Security's code base.

Related gh-7154

@rwinch rwinch added the status: ideal-for-contribution An issue that we actively are looking for someone to help us with label Jul 26, 2019
@eddumelendez
Copy link
Contributor

Hi @rwinch, do you think this is good for first-timers-only?

@rwinch
Copy link
Member Author

rwinch commented Aug 5, 2019

Thanks for asking @eddumelendez I think it is likely a lot of code to touch for a first timers.

@rwinch rwinch changed the title Remove internal Optional usage in favor of null checksgtgt Remove internal Optional usage in favor of null checks Aug 9, 2019
krisztian-toth added a commit to krisztian-toth/spring-security that referenced this issue Aug 22, 2019
krisztian-toth added a commit to krisztian-toth/spring-security that referenced this issue Aug 22, 2019
…ster' of https://github.com/watsta/spring-security into spring-projectsgh-7155-remove-optional-usage

# Conflicts:
#	oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java
@eleftherias
Copy link
Contributor

As mentioned in the PR, Optional is still being used in the following files:

  • org.springframework.security.oauth2.client.web.reactive.function.client.OAuth2AuthorizedClientResolver
  • org.springframework.security.oauth2.client.web.reactive.result.method.annotation.OAuth2AuthorizedClientResolver
  • org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction
    Since an additional object needs to be created regardless, in this situation, it is reasonable to keep using Optionals instead of creating an object of a different type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants