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

Avoid LinkedList performance issues through use of ArrayDeque #25652

Closed
jhoeller opened this issue Aug 27, 2020 · 2 comments
Closed

Avoid LinkedList performance issues through use of ArrayDeque #25652

jhoeller opened this issue Aug 27, 2020 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@jhoeller
Copy link
Contributor

jhoeller commented Aug 27, 2020

Triggered by gh-25650 which replaces LinkedList all over the place in the 5.3 codebase, we've identified several spots where the use of ArrayDeque instead of LinkedList specifically avoids performance issues (e.g. for a larger number of elements). In particular, StringUtils.cleanPath, FastByteArrayOutputStream and ParseState benefit from such a change in the 5.2.x line as well.

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Aug 27, 2020
@jhoeller jhoeller added this to the 5.2.9 milestone Aug 27, 2020
@jhoeller jhoeller self-assigned this Aug 27, 2020
@jhoeller jhoeller changed the title Avoid performance issues through use of ArrayDeque instead of LinkedList Avoid LinkedList performance issues through use of ArrayDeque Aug 27, 2020
@dreis2211
Copy link
Contributor

@jhoeller Could you elaborate on the for size determination aspect?

LinkedList:

    public int size() {
        return size;
    }

vs.

ArrayDeque

    public int size() {
        return (tail - head) & (elements.length - 1);
    }

Naively, the implementation of ArrayDeque seems to be more expensive - or let's say it differently. Both seem to be O(1). Am I missing something?

@jhoeller
Copy link
Contributor Author

That's true, of course, not sure how I arrived at that :-) I'll remove the size determination part from the rationale above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants