-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Improve Iterators.single #122875
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
Merged
original-brownbear
merged 1 commit into
elastic:main
from
original-brownbear:cleanup-single-iter
Feb 18, 2025
Merged
Improve Iterators.single #122875
original-brownbear
merged 1 commit into
elastic:main
from
original-brownbear:cleanup-single-iter
Feb 18, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using an anonymous class here doesn't compile as expected.
The resulting class comes out as:
```
class Iterators$1 implements java.util.Iterator<T> {
private T value;
final java.lang.Object val$element;
Iterators$1(java.lang.Object);
```
which seemingly also does not get fixed by the JIT compiler, judging by
heap dumps. Lets just use a named class to clean this up and make things
a bit more compact and save some heap as well here and there potentially.
Collaborator
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
DaveCTurner
approved these changes
Feb 18, 2025
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me, but I don't see the extra field in my compiler output - what am I missing?
Compiled from "Iterators.java"
class org.elasticsearch.common.collect.Iterators$1 implements java.util.Iterator<T> {
final java.lang.Object val$element;
org.elasticsearch.common.collect.Iterators$1(java.lang.Object);
Code:
0: aload_0
1: aload_1
2: putfield #1 // Field val$element:Ljava/lang/Object;
5: aload_0
6: invokespecial #7 // Method java/lang/Object."<init>":()V
9: aload_0
10: aload_0
11: getfield #1 // Field val$element:Ljava/lang/Object;
14: invokestatic #13 // Method java/util/Objects.requireNonNull:(Ljava/lang/Object;)Ljava/lang/Object;
17: putfield #19 // Field value:Ljava/lang/Object;
20: return
public boolean hasNext();
Code:
0: aload_0
1: getfield #19 // Field value:Ljava/lang/Object;
4: ifnull 11
7: iconst_1
8: goto 12
11: iconst_0
12: ireturn
public T next();
Code:
0: aload_0
1: getfield #19 // Field value:Ljava/lang/Object;
4: astore_1
5: aload_0
6: aconst_null
7: putfield #19 // Field value:Ljava/lang/Object;
10: aload_1
11: areturn
}
Contributor
|
Ah oops forgot |
Contributor
Author
|
Thanks David! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
:Core/Infra/Core
Core issues without another label
>non-issue
Team:Core/Infra
Meta label for core/infra team
v9.1.0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Random find from debugging: using an anonymous class here doesn't compile as expected. The resulting class comes out as:
which seemingly also does not get fixed by the JIT compiler, judging by heap dumps. Lets just use a named class to clean this up and make things a bit more compact and save some heap as well here and there potentially.