This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch 3.6-pathretraction in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 961699659fc69a6ba5418e24c00fd27ba11bc14a Author: Stephen Mallette <[email protected]> AuthorDate: Fri Mar 1 09:25:09 2024 -0500 Improve performance of PathRetractionStrategy Helpful for traversals with lots of children where labels don't need to propagate. CTR --- CHANGELOG.asciidoc | 1 + .../traversal/strategy/optimization/PathRetractionStrategy.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 6f2e3d63c3..e6f71e13bc 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Fixed a bug in Gremlin.Net for .NET 8 that led to exceptions: `InvalidOperationException: Enumeration has not started. Call MoveNext.` * Fixed message requestId serialization in `gremlin-python`. +* Improved performance of `PathRetractionStrategy` for traversals that carry many children, but don't hold many labels to propogate. * Fixed bug in bytecode translation of `g.tx().commit()` and `g.tx().rollback()` in all languages. * Improved error message from `JavaTranslator` by including exception source. * Added missing `short` serialization (`gx:Int16`) to GraphSONV2 and GraphSONV3 in `gremlin-python`. diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java index cd29b28820..fc4e845797 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java @@ -249,6 +249,10 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav } private void applyToChildren(final Set<String> keepLabels, final List<Traversal.Admin<Object, Object>> children) { + // if there are no labels to keep, then there no need to iterate all the children because we won't be + // adding anything PathProcessor keepLabels - avoids the added recursion + if (keepLabels.isEmpty()) return; + for (final Traversal.Admin<Object, Object> child : children) { TraversalHelper.applyTraversalRecursively(trav -> addLabels(trav, keepLabels), child); }
