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

Optimize Map methods in ServletAttributesMap #32189

Conversation

kilink
Copy link
Contributor

@kilink kilink commented Feb 2, 2024

ServletAttributesMap inherited default implementations of the size and isEmpty methods from AbstractMap which delegates to the Set returned by entrySet. ServletAttributesMap's entrySet method made this fairly expensive, since it would copy the attributes to a List, then use a Stream to build the Set. To avoid the cost, add implementations of isEmpty / size that don't need to call entrySet at all. Additionally, change entrySet to return a Set view that simply lazily delegates to the underlying servlet request for iteration.

ServletAttributesMap inherited default implementations of the size and isEmpty methods
from AbstractMap which delegates to the Set returned by entrySet. ServletAttributesMap's
entrySet method made this fairly expensive, since it would copy the attributes to a List,
then use a Stream to build the Set. To avoid the cost, add implementations of isEmpty /
size that don't need to call entrySet at all. Additionally, change entrySet to return
a Set view that simply lazily delegates to the underlying servlet request for iteration.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 2, 2024
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 2, 2024
@bclozel bclozel added this to the 6.1.x milestone Feb 2, 2024
@bclozel bclozel self-assigned this Feb 2, 2024
@bclozel bclozel added for: backport-to-6.0.x status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x labels Feb 5, 2024
@bclozel bclozel closed this in 0fdf759 Feb 5, 2024
@bclozel bclozel modified the milestones: 6.1.x, 6.1.4 Feb 5, 2024
@bclozel
Copy link
Member

bclozel commented Feb 5, 2024

Thanks @kilink for your contribution, this has been merged in main and will be backported to 6.0.x as well in #32197

bclozel added a commit that referenced this pull request Feb 5, 2024
@kilink kilink deleted the servlet-parameters-map-optimization branch February 5, 2024 18:17
@jhoeller jhoeller added type: enhancement A general enhancement and removed type: task A general task labels Feb 6, 2024
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) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants