I've just found out that main page of custom theme im developing does 150 db queries on every load (what takes even 2.5 seconds).
Many of them come from functions.php, and are caused by for example add_image_size() or register_nav_menus() functions. However, when I deleted these functions website still had functioned properly.
From what I understand, these functions just write some informations to database and nothing bad would happen if I seriously deleted them for ever (correct me if I'm wrong) because these informations are already there. For example, when I deleted register_nav_menus() (where I'm registering several menus), number of queries went down to ~120 and website still functioned properly.
Of course deleting these functions doesn't seem like the best idea (what if I want to start using my theme with clean database). So is there any way to check if for example these menus or image sizes have already been declared and exist in database? And if so, do not execute that register_nav_menus() or add_image_size() functions? Or wordpress is already doing it internally? Would this check cause additional database hit?
This is the first theme I'm developing and I would be grateful for any tips on how to lessen db queries in this case.