You'll get a full answer
here[
^].
To summarise:
0. Plan the structure of your app first.
1. Write good solid code.
2. Once everything is working, refactor to remove slow or inefficient code.
Wow! It's the same as building a good product ina ny other framework.