Side effect of sideEffect (TP3)

57 views
Skip to first unread message

Matt Frantz

unread,
Mar 24, 2015, 7:57:52 PM3/24/15
to gremli...@googlegroups.com
I use sideEffect to produce debug logging (System.err.println) during traversal execution.  I can enable or disable this logging with a runtime switch.  When disabled, I want it so that the sideEffect steps are not even added to the Traversal, so there is no overhead.

I've noticed that I sometimes get different behavior when the logging sideEffects are not added, so I wonder whether there is some kind of traversal rewriting or optimization happening, something that the addition of sideEffect steps would somehow change.

It turns out that in every case (so far), the desired behavior occurs when the sideEffect is present.  For a workaround, I have added a no-op sideEffect{ it -> } instead of the logging sideEffect when logging is disabled.

I wish I had a simple repro, but the problem seems to occur once the traversal has reached a certain level of complexity.  In one scenario, I added a "select" step (which effectively selected the data that was already in the traverser ... sort of an "assert"), and that seemed to cause the problem to appear.

Does this sound like something that is expected behavior, i.e. sideEffect impacting traversal execution?

Full disclosure: I'm using an old 3.0.0 snapshot, specifically the last SonaType snapshot (2015-02-06).  I'll be migrating to a more recent snapshot shortly.

Stephen Mallette

unread,
Mar 25, 2015, 8:08:40 AM3/25/15
to gremli...@googlegroups.com
You mentioned you "get different behavior when the logging sideEffects are not added" - I wouldn't expect a sideEffect() to affect the traversal behavior.  You don't really say what the different behavior is between sideEffect() and no-sideEffect().   Could you elaborate on this problem a little?   

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f12d9314-ea6a-461a-bacc-d169fd167210%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Frantz

unread,
Mar 25, 2015, 12:22:23 PM3/25/15
to gremli...@googlegroups.com
I have a complex traversal that produces a single boolean result.  Without debug logging, it is hard to tell what is going wrong when something goes wrong.  So it is a "Heisenbug".

In the past, I have successfully inserted my own debug statements within the TP3 source code in order to watch the execution of a traversal.  I may resort to such techniques to drill down on this problem.  Since the JVM is embedded in a NodeJS server (via the gremlin-v3 NodeJS package), using the Java debugger would be cumbersome, if not impossible.

By the way, I would love for there to be a "trace logging" mode of traversal execution!  However, that is less a feature than a programming discipline, so this requirement is hard to impose on a mature code base.

Anyway, if sideEffects really shouldn't affect traversal behavior, then I'll pursue a simple repro.  I can't really share my traversal as-is on this public forum, since it implements proprietary business logic.

Stephen Mallette

unread,
Mar 25, 2015, 12:28:54 PM3/25/15
to gremli...@googlegroups.com
So - if I understand you correctly, you are basically saying that the Traversal returns "true" under normal circumstances, but if you add the logging sideEffect() steps, you suddenly might get a "false"?

Matt Frantz

unread,
Mar 25, 2015, 1:12:36 PM3/25/15
to gremli...@googlegroups.com
I have unit tests that test both "true" and "false" outcomes.  In my case, "true" means that the traversal produces something (i.e. hasNext returns true).  In every case (so far), the desired behavior (whether true or false) is displayed when the logging sideEffects are in place.  When they are removed, I sometimes see tests fail.  I haven't noticed a pattern of which type of test (true or false) fails more often.

Stephen Mallette

unread,
Mar 25, 2015, 1:25:19 PM3/25/15
to gremli...@googlegroups.com
That sounds really fishy - very odd that you get the expected output when sideEffect() logging is present, but incorrect output without it. If you can come up with some repro steps, that would be really helpful as I'm not sure what to make of that otherwise.  

Reply all
Reply to author
Forward
0 new messages