How to optimise my script, a script for opening new a new emacs instance only if no instance is present
I usually just run

emacsclient -a emacs FILE


or

emacsclient -a SHELL-SCRIPT-WHICH-STARTS-EMACS-WITH-PARAMETERS FILE


and let emacsclient figure out the rest.