Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Android] ArrayList is faster than LinkedList for reasonable N. #50767

Closed
wants to merge 4 commits into from

Conversation

jonahwilliams
Copy link
Member

Fixes flutter/flutter#143721

Java LinkedList is just slooow.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@@ -735,7 +735,7 @@ private PerImageReader getActiveReader() {
// Create a new ImageReader and add it to the queue.
return getOrCreatePerImageReader(createImageReader());
}
return imageReaderQueue.peekLast();
return imageReaderQueue.get(imageReaderQueue.size() - 1);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check length here, the peek methods return null if the size isn't enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that it much matters, but fun drive by comment to say you could use an ArrayDeque here instead if you wanted to keep the same convenience right? (they both implement the double ended queue interface)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, I will try that.

@chinmaygarde
Copy link
Member

Are we making progress on this? Seems like a generally good thing to do.

@chinmaygarde
Copy link
Member

Closing as stale.

auto-submit bot pushed a commit that referenced this pull request Apr 17, 2024
…er with ArrayDeques (#51494)

Inspired by #50767.

[As their documentation notes](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html), `ArrayDeque`s are generally faster than LinkedList when used as a queue.

Fixes flutter/flutter#143721

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
reidbaker pushed a commit to reidbaker/engine that referenced this pull request May 1, 2024
…er with ArrayDeques (flutter#51494)

Inspired by flutter#50767.

[As their documentation notes](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html), `ArrayDeque`s are generally faster than LinkedList when used as a queue.

Fixes flutter/flutter#143721

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
reidbaker pushed a commit to reidbaker/engine that referenced this pull request May 1, 2024
…er with ArrayDeques (flutter#51494)

Inspired by flutter#50767.

[As their documentation notes](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html), `ArrayDeque`s are generally faster than LinkedList when used as a queue.

Fixes flutter/flutter#143721

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] LinkedList iteration in ImageProducer is surprisingly slow
3 participants