Optimization of Delete quey

I am trying to delete few duplicate relationships that got created under same nodes.. I mean node A Is connected to node B with relationship R two times. Hence I have to delete one relationship. To do that I have written a query like

Match p=()-[r: relationship]->()
with r.id as id, collect(r) as branches where size(branches)>1
Foreach(n IN TAIL(branches) | Delete n)

how can I optimize this query? There are millions of records to be deleted.
Any suggestions would be great for me.

I am using Neo4j version 3.5.

Given you are on 3.5, you can put the DELETE inside apoc.periodic.iterate, and do the deletes in batches and opt to use multiple threads.

You can also alter the MATCH so as to only match on duplicate relationships, by using an exists predicate function.

See this Stack Overflow answer for details.