Your script looks quite comprehensive, and it's good that you are considering optimization. Here are some suggestions to optimize and improve your script:
1. Use Dependency Injection:
Instead of using ...
Start by not using object manager but dependency injectrion.
Then in term of performance i would say
The closest you are from the system the fastest it is.
That means accessing threw repositories will ...
it can be problem with url_rewrite table. When you want to solve problem, pls check few points:
Whether url_key in existing products is unique
Whether url_key in product which you want to import is ...