Is is ok to generate GraphTraversalSource on demand by using TinkerVertex.getGraph().traversal() ?

Is is ok to generate GraphTraversalSource on demand by using TinkerVertex.getGraph().traversal() ? Since GraphTraversalSource is reusable, maybe it is a bad practice ?
1 Reply
spmallette
spmallette2y ago
Speaking specifically to your example that uses TinkerGraph and gets the Graph from TinkerVertex I suppose that's not massively costly but you are producing throwaway GraphTraversalSource objects which will add to the number of things in memory to garbage collect at some point. I'm not sure of the real cost there offhand. This approach does go against recommendations which is to re-use your GraphTraversalSource and might be more expensive for other cases outside of an embedded TinkerGraph situation so if you ever switched graph systems you could run afoul of this choice. Also, since the approach opposes convention, it's possible that something could change in TinkerPop in the future that might make this approach a truly bad practice or could be blocked wholly in some other way.
Want results from more Discord servers?
Add your server