Efficiency improvement for edgelist/graph creation