[Gremlin3] RFC for Removing Shorthand Property Access Notation in Gremlin-Groovy

44 views
Skip to first unread message

Marko Rodriguez

unread,
Apr 22, 2014, 9:13:30 AM4/22/14
to gremli...@googlegroups.com
Hello,

In Gremlin2, you can do this:


We can make this possible in Gremlin3, however it is problematic for people that rely on this shorthand in production systems as its about 5x slower than the direct method call:

v.getValue('name')

One solution is to make use of the following convention in Gremlin3 which is faster than v.name in Groovy:

v['name']

----------------------

gremlin> v.name
==>marko
gremlin> v['name']
==>marko
gremlin> v.getValue('name')
==>marko

Here are the respective runtimes of the 3 notations above in Gremlin3 for 100,000 calls.

v.name -> 225ms
v['name'] -> 41ms
v.getValue('name') -> 35ms

I think we should get rid of v.name and provide v['name'].

Thoughts?,
Marko.

Matthias Broecheler

unread,
Apr 22, 2014, 12:51:15 PM4/22/14
to gremli...@googlegroups.com
Hey Marko,

quick question: When the script is pre-compiled and you only pass in the arguments, is there still a big difference?
Thanks,
Matthias


--
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.
For more options, visit https://groups.google.com/d/optout.



--
Matthias Broecheler
http://www.matthiasb.com

Marko Rodriguez

unread,
Apr 22, 2014, 12:53:12 PM4/22/14
to gremli...@googlegroups.com
Yes. v.name will throw a "NoSuchFieldException." In Groovy, you can intercept this and then issue "return g.getValue(fieldName)". So, its always a throw/catch.

Borys Pierov

unread,
Apr 24, 2014, 5:17:15 AM4/24/14
to gremli...@googlegroups.com
Hi Marko,

IMHO it's a great idea. :)

Though I'm a bit curios why v['name'] is slower than v.getValue('name')? And although performance characteristic is not so big shouldn't only the most fast access option be left and all others being removed?

Marko Rodriguez

unread,
Apr 24, 2014, 10:10:24 AM4/24/14
to gremli...@googlegroups.com
Hi,

The reason that v['name'] is faster is because it directly calls the Groovy MetaClass of Element which maintain the method getAt(). In Groovy, you get methods like plus(), minus(), modulo(), … for which you can define for common language constructs such as:

>>, <<, [], +, - , %, /, !, etc.

There is no exception handling in this case so it is fast. However it is not a method on the Element class, but on the Element MetaClass so thats why its a bit slower than the direct call to v.getValue('name').

I hope that is clear.

Thanks,
Marko.
Reply all
Reply to author
Forward
0 new messages