Background:
In one of the SO posts it is recommended to use Traversal API than Graph API to make mutation. So I tried out some tests and found Graph API seemed to be faster, I do totally believe the advice but I am trying to understand how its better.
I did try googling but did not find a similar post
Testing:
Query 1: Executed in 0.19734525680541992 seconds
g.addV('Test').property('title1', 'abc').property('title2', 'abc')
Query 2: Executed in 0.13838958740234375 seconds
graph.addVertex(label, "Test", "title1", "abc", "title2", "abc")
Question:
- Which one is better and why?
- If both are same then why the performance difference?
The Graph API is meant for graph providers and the Traversal API (which is really the Gremlin language) is meant for users. You definitely reduce the portability of your code by using the Graph API. The "server graphs" out there, like Amazon Neptune, DSE Graph, CosmosDB, etc., present environments that don't give you access to the Graph API and therefore you would never be able to switch to those if you felt like doing so. You also start to build your application around two APIs thus creating a non-unified approach to your development (i.e. in some cases you will pass around a
Graph
object for the Graph API and in some casesGraphTraversalSource
for the Traversal API).I don't know how you executed your tests, but it doesn't surprise me that much that you see a small difference in performance in micro-benchmarks. There is some cost to the Traversal API, but TinkerPop continues to improve in that area - consider the recently closed TINKERPOP-1950 as an example of something recent. I don't know for sure that this will help for your specific benchmark, as benchmarks are tricky things, but the point is that we haven't stopped trying to optimize in that area.
Finally, if discussions in the TinkerPop community continue in the direction they have been going for the past year, I would fully expect to see the Graph API disappear in TinkerPop 4.x. There is no timeline for this release and it is only in the discussion phase, but I would imagine that if you intend for your application to live for many years to come, this information might be of interest to you.