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

Replace common usage of LinkedList with ArrayList/ArrayDeque [SPR-17037] #21575

Closed
spring-projects-issues opened this issue Jul 13, 2018 · 4 comments
Assignees
Labels
in: core type: task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 13, 2018

Сергей Цыпанов opened SPR-17037 and commented

LinkedList is an outdated collection which is still used in the code of Spring Framework as queue or list. LinkedList consumes more memory and is generally slower than ArrayList/ArrayDeque. This can cause perormance problems, see e.g. #1873.

In most of cases it's possible to replace LinkedList with ArrayList/ArrayDeque after proper review.


Affects: 5.0.7

Referenced from: commits 9c08a48, 11fc086

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2018

Juergen Hoeller commented

I've replaced several occurrences of LinkedList with ArrayList and in a few cases with ArrayDeque.

However, plenty of LinkedList usage remains: in particular for entries that are potentially multi-element but are likely to only contain one entry, and for entries that are mutable for customization purposes but are likely to remain empty. LinkedList has a distinct advantage there in not occupying any space if empty (in contrast to ArrayDeque), and no wasteful 10-element array in case of a single entry. This is the remaining sweet spot for LinkedList, from my perspective.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2018

Сергей Цыпанов commented

Thanks!

BTW, is there any ticket here for continuous performance improvements? I mean one which can be used to bind multiple pull-requests to.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2018

Juergen Hoeller commented

We could create a ticket for remaining minor performance improvements for 5.1 still. Otherwise specific tickets are fine since they can be individually scheduled then.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 18, 2018

Juergen Hoeller commented

Backported to 5.0.8 since it is completely internal and includes a couple of worthwhile optimizations, including pre-sizing of certain ArrayList instances.

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

No branches or pull requests

2 participants