Skip to content

Commit a2f6c47

Browse files
lipidohlfernandez
authored andcommitted
Improves DAG perfomance in binded foreachs
Binded foreachs need a DAG entry per foreach iteration, causing scalability problems in large foreachs when computing dependencies. This commit alleviates this by adding a dependencies cache with dependency computation results that do not changes while the DAG is not modified.
1 parent 3b73d60 commit a2f6c47

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed

cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>org.sing_group</groupId>
1111
<artifactId>compi</artifactId>
12-
<version>1.3.4</version>
12+
<version>1.3.5</version>
1313
<!--
1414
WARNING: change version using (in the parent project):
1515
mvn versions:set -DnewVersion=[new_version]

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>org.sing_group</groupId>
1212
<artifactId>compi</artifactId>
13-
<version>1.3.4</version>
13+
<version>1.3.5</version>
1414
<!--
1515
WARNING: change version using (in the parent project):
1616
mvn versions:set -DnewVersion=[new_version]

core/src/main/java/org/sing_group/compi/core/TasksDAG.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
import static java.util.function.Function.identity;
2424

2525
import java.util.Collection;
26+
import java.util.HashMap;
2627
import java.util.HashSet;
2728
import java.util.Map;
2829
import java.util.Set;
2930
import java.util.concurrent.ConcurrentHashMap;
3031
import java.util.stream.Collectors;
3132

33+
import org.sing_group.compi.core.loops.ForeachIteration;
3234
import org.sing_group.compi.core.loops.ForeachIterationDependency;
3335
import org.sing_group.compi.core.pipeline.Foreach;
3436
import org.sing_group.compi.core.pipeline.Task;
@@ -37,7 +39,13 @@ public class TasksDAG {
3739

3840
private final Map<Task, Set<Dependency<?>>> dag = new ConcurrentHashMap<>();
3941

42+
private Map<Task, Set<Dependency<?>>> dependantsCache = new HashMap<>();
43+
private Map<Task, Set<Dependency<?>>> dependenciesCache = new HashMap<>();
44+
4045
public Set<Dependency<?>> getDependantsOfTask(Task t) {
46+
if (dependantsCache.containsKey(t))
47+
return dependantsCache.get(t);
48+
4149
Set<Dependency<?>> dependantsOfTask = new HashSet<Dependency<?>>();
4250
if (this.dag.get(t) == null) {
4351
return new HashSet<>();
@@ -51,6 +59,9 @@ public Set<Dependency<?>> getDependantsOfTask(Task t) {
5159
).collect(Collectors.toSet())
5260
);
5361
}
62+
63+
dependantsCache.put(t, dependantsOfTask);
64+
5465
return dependantsOfTask;
5566
}
5667

@@ -62,6 +73,9 @@ public Set<Dependency<?>> getDependantsOfTask(Task t) {
6273
* @return Tasks that task depends on
6374
*/
6475
public Set<Dependency<?>> getDependenciesOfTask(Task task) {
76+
if (dependenciesCache.containsKey(task))
77+
return dependenciesCache.get(task);
78+
6579
final Set<Dependency<?>> dependencies = new HashSet<>();
6680
dag.keySet().forEach(t -> {
6781
final Set<Dependency<?>> dependants = getDependantsOfTask(t);
@@ -74,6 +88,7 @@ public Set<Dependency<?>> getDependenciesOfTask(Task task) {
7488
;
7589
});
7690

91+
dependenciesCache.put(task, dependencies);
7792
return dependencies;
7893
}
7994

@@ -105,6 +120,7 @@ public boolean dependenciesAreMet(final Task task) {
105120

106121
public void removeDependency(Task t, Task dependant) {
107122
this.dag.get(t).removeIf(d -> d.getDependantTask().equals(dependant));
123+
clearCache();
108124
}
109125

110126
public void addDependency(Task task, Task dependant, boolean isIterationDependency) {
@@ -117,5 +133,12 @@ public void addDependency(Task task, Task dependant, boolean isIterationDependen
117133
this.dag.get(task).add(
118134
isIterationDependency ? new ForeachIterationDependency((Foreach) task, (Foreach) dependant) : new Dependency<Task>(task, dependant)
119135
);
136+
clearCache();
137+
}
138+
139+
private void clearCache() {
140+
this.dependantsCache.clear();
141+
this.dependenciesCache.clear();
142+
120143
}
121144
}

dk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>org.sing_group</groupId>
1111
<artifactId>compi</artifactId>
12-
<version>1.3.4</version>
12+
<version>1.3.5</version>
1313
<!--
1414
WARNING: change version using (in the parent project):
1515
mvn versions:set -DnewVersion=[new_version]

e2e-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<parent>
1010
<groupId>org.sing_group</groupId>
1111
<artifactId>compi</artifactId>
12-
<version>1.3.4</version>
12+
<version>1.3.5</version>
1313
<!--
1414
WARNING: change version using (in the parent project):
1515
mvn versions:set -DnewVersion=[new_version]

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>org.sing_group</groupId>
77
<artifactId>compi</artifactId>
88
<packaging>pom</packaging>
9-
<version>1.3.4</version>
9+
<version>1.3.5</version>
1010
<!-- WARNING: change version using (in the parent project): mvn versions:set -DnewVersion=[new_version] mvn versions:commit This will change the version
1111
in all modules at-once -->
1212

0 commit comments

Comments
 (0)