Skip to content

Commit ee2e54e

Browse files
author
Jörg Kubitz
committed
[performance] Avoid O(n^2) in DeadlockDetector.lockAcquired()
With n conflicting rules. Has been observed as severe hotspot in workspace with n= ~1000 projects Functionality is tested with IJobManagerTest.testTransferToJobWaitingOnChildRule()
1 parent d3dd4bf commit ee2e54e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/DeadlockDetector.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.io.PrintWriter;
1717
import java.io.StringWriter;
1818
import java.util.ArrayList;
19+
import java.util.Collection;
20+
import java.util.HashSet;
1921
import org.eclipse.core.internal.runtime.RuntimeLog;
2022
import org.eclipse.core.runtime.Assert;
2123
import org.eclipse.core.runtime.IStatus;
@@ -304,14 +306,13 @@ void lockAcquired(Thread owner, ISchedulingRule lock) {
304306
* or conflict with a lock the given lock will acquire implicitly
305307
* (locks are acquired implicitly when a conflicting lock is acquired)
306308
*/
307-
ArrayList<ISchedulingRule> conflicting = new ArrayList<>(1);
309+
Collection<ISchedulingRule> conflicting = new HashSet<>(1);
308310
//only need two passes through all the locks to pick up all conflicting rules
309311
int NUM_PASSES = 2;
310312
conflicting.add(lock);
311313
graph[threadIndex][lockIndex]++;
312314
for (int i = 0; i < NUM_PASSES; i++) {
313-
for (int k = 0; k < conflicting.size(); k++) {
314-
ISchedulingRule current = conflicting.get(k);
315+
for (ISchedulingRule current : conflicting) {
315316
for (int j = 0; j < locks.size(); j++) {
316317
ISchedulingRule possible = locks.get(j);
317318
if (!conflicting.contains(possible) && current.isConflicting(possible)) {

0 commit comments

Comments
 (0)