how can i improve script execution time
If blender freezes while script execution, you should check performance using build-in modules.

In some cases you can cache function return using functools.lru_cache.

The one way to get more resources is using multiprocessing.