Re: Java Heap Space - Vertex.edges
Can you take a look at this blog from Boxuan Li: https://li-boxuan.medium.com/janusgraph-deep-dive-part-3-speed-up-edge-queries-3b9eb5ba34f8
In general, it is better to use the TinkerPop API starting with g.V(). This makes sure you do not skip query optimizations. In addition, it makes your code more portable with respect to other TinkerPop-compatible graph systems.
I am not sure though if this will really help for your use case, but give it a try!
Best wishes, Marc