Skip to content

Commit bc340cc

Browse files
committed
Fix some perfomance issues: get rid of nested transactions, do explicit autoboxing
1 parent e4101d6 commit bc340cc

5 files changed

Lines changed: 18 additions & 26 deletions

File tree

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/impl/Neo4jGraph.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ public void setInterestingnessStrategy(InterestingnessStrategy is) {
284284
* order, to assign ranks and scores to nodes.
285285
*/
286286
protected void analyze() {
287-
// Rank the graph.
288-
execute(e -> new AnalyzeCommand(rootIterator()).execute(e));
287+
ResourceIterator<Node> roots;
288+
try (Transaction tx = service.beginTx()) {
289+
roots = rootIterator();
290+
new AnalyzeCommand(roots).execute(service);
291+
tx.success();
292+
}
289293
}
290294

291295
@Override

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/impl/NodeLabels.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ public enum NodeLabels implements Label {
1212
SOURCE,
1313
NODE,
1414
BUBBLE_SOURCE,
15-
BUBBLE_SINK
1615
}

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/impl/RelTypes.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ public enum RelTypes implements RelationshipType {
1111
NEXT,
1212
SOURCE,
1313
MUTATION,
14-
BUBBLE_SINK_OF,
1514
BUBBLE_SOURCE_OF
1615
}

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/impl/command/AnalyzeCommand.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.neo4j.graphdb.Node;
99
import org.neo4j.graphdb.Relationship;
1010
import org.neo4j.graphdb.ResourceIterator;
11-
import org.neo4j.graphdb.Transaction;
1211
import org.neo4j.graphdb.traversal.InitialBranchState;
1312
import org.neo4j.graphdb.traversal.Uniqueness;
1413

@@ -52,13 +51,8 @@ public Iterable<Node> topologicalOrder(GraphDatabaseService service) {
5251

5352
@Override
5453
public void execute(GraphDatabaseService service) {
55-
try (
56-
Transaction tx = service.beginTx();
57-
) {
58-
for (Node n : topologicalOrder(service)) {
59-
rankDest(n);
60-
}
61-
tx.success();
54+
for (Node n : topologicalOrder(service)) {
55+
rankDest(n);
6256
}
6357
}
6458

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/impl/command/TopologicalPathExpander.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,48 +94,48 @@ private Set<Long> getSourcesToPropagate(Node from) {
9494
// This function accumulates unclosed bubble sources from a mapping of incoming edge ids.
9595
Set<Long> propagatedSources = new HashSet<>();
9696
for (Relationship in : ins) {
97-
propagatedSources.addAll(relIDtoSourceIDs.remove(in.getId()).stream()
97+
propagatedSources.addAll(relIDtoSourceIDs.remove(Long.valueOf(in.getId())).stream()
9898
.filter(source -> bubbleSourceIDtoEndIDs.get(source) != null)
9999
.collect(Collectors.toList()));
100100
}
101101
return propagatedSources;
102102
}
103103

104-
private void advanceEnds(long bubbleSource, Node endnode) {
104+
private void advanceEnds(Long bubbleSource, Node endnode) {
105105
Set<Long> pathEndIDs = bubbleSourceIDtoEndIDs.get(bubbleSource);
106106
if (pathEndIDs != null) {
107-
pathEndIDs.remove(endnode.getId());
107+
pathEndIDs.remove(Long.valueOf(endnode.getId()));
108108

109109
// FIXME: we add twice here in most cases.
110110
endnode.getRelationships(RelTypes.NEXT, Direction.OUTGOING)
111-
.forEach(rel -> pathEndIDs.add(rel.getEndNode().getId()));
111+
.forEach(rel -> pathEndIDs.add(Long.valueOf(rel.getEndNode().getId())));
112112
}
113113
}
114114

115115
private void createBubbleSource(Node n, Set<Long> toPropagate) {
116116
int outDegree = n.getDegree(RelTypes.NEXT, Direction.OUTGOING);
117117
if (outDegree >= 2) {
118118
Set<Long> pathEnds = new HashSet<>(outDegree);
119-
toPropagate.add(n.getId());
119+
toPropagate.add(Long.valueOf(n.getId()));
120120

121121
n.addLabel(NodeLabels.BUBBLE_SOURCE);
122122
n.getRelationships(RelTypes.NEXT, Direction.OUTGOING)
123-
.forEach(rel -> pathEnds.add(rel.getEndNode().getId()));
123+
.forEach(rel -> pathEnds.add(Long.valueOf(rel.getEndNode().getId())));
124124

125-
bubbleSourceIDtoEndIDs.put(n.getId(), pathEnds);
125+
bubbleSourceIDtoEndIDs.put(Long.valueOf(n.getId()), pathEnds);
126126
}
127127
}
128128

129129
private void propagateSourceIDs(Set<Long> propagatedUnique, Relationship out) {
130-
relIDtoSourceIDs.put(out.getId(), propagatedUnique);
130+
relIDtoSourceIDs.put(Long.valueOf(out.getId()), propagatedUnique);
131131
}
132132

133133
private void createBubbleSink(Node n) {
134134
int degree = n.getDegree(RelTypes.NEXT, Direction.INCOMING);
135135
if (degree >= 2) {
136136
Set<Long> bubbleSourceID = new HashSet<>();
137137
for (Relationship in : n.getRelationships(RelTypes.NEXT, Direction.INCOMING)) {
138-
for (long sourceID : relIDtoSourceIDs.get(in.getId())) {
138+
for (Long sourceID : relIDtoSourceIDs.get(Long.valueOf(in.getId()))) {
139139
if (bubbleSourceIDtoEndIDs.get(sourceID).size() == 1) {
140140
bubbleSourceID.add(sourceID);
141141
}
@@ -145,13 +145,9 @@ private void createBubbleSink(Node n) {
145145
if (bubbleSourceIDtoEndIDs.get(id).size() == 1) {
146146
bubbleSourceIDtoEndIDs.remove(id);
147147
}
148-
Node bubbleSource = n.getGraphDatabase().getNodeById(id);
149-
n.createRelationshipTo(bubbleSource, RelTypes.BUBBLE_SINK_OF);
148+
Node bubbleSource = n.getGraphDatabase().getNodeById(id.longValue());
150149
bubbleSource.createRelationshipTo(n, RelTypes.BUBBLE_SOURCE_OF);
151150
});
152-
if (bubbleSourceID.size() != 0) {
153-
n.addLabel(NodeLabels.BUBBLE_SINK);
154-
}
155151
}
156152
}
157153

0 commit comments

Comments
 (0)