Skip to content
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

Improve performance of canRead() in HttpMessageReader's #30192

Closed

Conversation

yuzawa-san
Copy link
Contributor

@yuzawa-san yuzawa-san commented Mar 25, 2023

  • A lot of the decoders use MimeType.ALL, so use MimeType.WILDCARD_TYPE for faster String.equals() using reference comparisons, specifically in MimeType.isWildcardType().
  • Move cheaper checks to the front of the canRead implementations. The media/mime checks appear to be cheaper than Class.isAssignableFrom which is cheaper than the ResolvableType checks, so putting them in the correct order (while preserving the and/or logic) gives an improvement.

before icicle graph for CPU from my stress test. this is for a JSON payload, thus the other readers should be skipped and take as little cpu as possible:
image

after (see how MultipartHttpMessageReader and FormHttpMessageReader have shrunk):
image

Use MimeType.WILDCARD_TYPE for faster String.equals().
Move cheaper checks to the front of the canRead implementations.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 25, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-feedback We need additional information before we can continue labels Mar 27, 2023
@rstoyanchev rstoyanchev self-assigned this Mar 28, 2023
@rstoyanchev rstoyanchev added this to the 6.0.8 milestone Mar 28, 2023
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 28, 2023
@rstoyanchev rstoyanchev changed the title Improve performance of HttpMessageReader.canRead() Improve performance of canRead() in HttpMessageReader's Apr 11, 2023
rstoyanchev pushed a commit that referenced this pull request Apr 11, 2023
Use MimeType.WILDCARD_TYPE for faster String.equals().
Move cheaper checks to the front of the canRead implementations.

See gh-30192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants