Skip to content

Commit deaaa2c

Browse files
authored
Perf improvement for applying MoveTreeComponent update action (#8675)
Measured 133ms when merging two trees of 100k nodes each. On the old code, I aborted measuring after 3 minutes. Thanks for noticing this good opportunity @philippotto :)
1 parent 0c02a88 commit deaaa2c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

webknossos-tracingstore/app/com/scalableminds/webknossos/tracingstore/tracings/skeleton/updating/SkeletonUpdateActions.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,17 @@ case class MoveTreeComponentSkeletonAction(nodeIds: List[Int],
168168
extends SkeletonUpdateAction
169169
with SkeletonUpdateActionHelper {
170170

171+
private lazy val nodeIdsSet = nodeIds.toSet
172+
171173
// this should only move a whole component,
172174
// that is disjoint from the rest of the tree
173175
override def applyOn(tracing: SkeletonTracing): SkeletonTracing = {
174176
val sourceTree = treeById(tracing, sourceId)
175177
val targetTree = treeById(tracing, targetId)
176178

177-
val (movedNodes, remainingNodes) = sourceTree.nodes.partition(nodeIds contains _.id)
179+
val (movedNodes, remainingNodes) = sourceTree.nodes.partition(n => nodeIdsSet.contains(n.id))
178180
val (movedEdges, remainingEdges) =
179-
sourceTree.edges.partition(e => nodeIds.contains(e.source) && nodeIds.contains(e.target))
181+
sourceTree.edges.partition(e => nodeIdsSet.contains(e.source) && nodeIdsSet.contains(e.target))
180182
val updatedSource = sourceTree.copy(nodes = remainingNodes, edges = remainingEdges)
181183
val updatedTarget =
182184
targetTree.copy(nodes = targetTree.nodes.concat(movedNodes), edges = targetTree.edges.concat(movedEdges))

0 commit comments

Comments
 (0)