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 IdentityMostlySingleton #3558

Closed
wants to merge 6 commits into from
Closed

Conversation

wmdietl
Copy link
Member

@wmdietl wmdietl commented Aug 4, 2020

No description provided.

state = State.ANY;
// Use ArrayList, but make sure to use reference comparisons.
set = new ArrayList<>();
Copy link
Member

@mernst mernst Aug 5, 2020

Choose a reason for hiding this comment

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

I am partial to the version in #3550 because the variable named set is a set, and because it's shorter -- it doesn't need to re-implement logic for add and contains and therefore I find it easier to read and understand. As a minor benefit, #3550 type-checks under the Nullness Checker without the need for assumptions about use of the set variable in other subclasses of AbstractMostlySingleton (namely, @MonotonicNonNull on that variable, which is necessary in this pull request).

state = State.ANY;
// Use ArrayList, but make sure to use reference comparisons.
Copy link
Member

Choose a reason for hiding this comment

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

In the other pull request, you said that you think using an array list is more efficient. Can you explain more why you think it is more efficient? MostlySingleton uses a HashSet, should we change that one to make it more efficient, too?

When I was debugging this code, I was very surprised that set was in fact an ArrayList. I wondered why that choice was made. Given that using an ArrayList and using List#contains is not the correct behavior, it made more sense to me to use an identity hash set. This also matches the implementation match MostlySingleton.

@smillst smillst assigned wmdietl and unassigned smillst Aug 5, 2020
@mernst mernst changed the title Correct implementation of IdentityMostlySingleton Optimize IdentityMostlySingleton Aug 5, 2020
@wmdietl wmdietl closed this Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants