-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[MNG-8575] Replace a list with O(N²) performance by O(N) at least during iteration. #2092
Conversation
3ab95ba
to
99ead65
Compare
It brings a related question. The following code also has a O(N²) performance cost if a large number N of sources are added through this method: private List<SourceRoot> sources = new CopyOnWriteArrayList<>();
public void addSourceRoot(SourceRoot source) {
if (!sources.contains(source)) {
sources.add(source);
}
} We could reduce the cost to O(N) by using |
Maybe we want two methods to add sources? And one could be a "batch" (several sources at once) to be used by Project Builder and other adding one by one like for example some plugin may be? Am unsure would the rate of second call justify complicating things.... |
A batch method would not fundamentally change the O(N²) nature of the operation, unless it temporarily copy the list in an hash set, in which case we lost the concurrency characteristics of I think that the first question still: do we need to care about concurrency or thread safety now, given that the rest of the class is not thread-safe? If no, we can just replace |
I don't think we need thread safety here. Thread safe
I don't think we do. We can defer that at the time we reverse the MavenProject implementation to be implemented on top of Project. |
…rate over all previous values every time that a new value is added.
…without iterating over all elements.
JIRA issue: MNG-8575
The use of
AbstractList
with an implementation that creates the whole list every time thatget(int)
is invoked implies that iterations over that list would have a performance cost of O(N²) where N is the number of elements. ExtendingAbstractSequentialList
instead brings back the performance cost to O(N) at least during iterations.