A possible cause when Sharepoint is very slow: Stored Procedure: proc_getwebnavstruct

Today I had a challange at work, after modifying an Angular application that uses the Search API and included some wildcards on the query then Sharepoint become unresponsive.

The first thing I though its I broke it with my modification, becase the results before were about 50, and after my change the results returned 2000 items, that was my initial thoughts.

However after digging deeper into the situation we found that one of the Out of the Box Stored Procedures was taking about 200 seconds to execute, the stored procedure is called: proc_getwebnavstruct

Before finding this we checked CPU and Memory in all servers, including Database servers, we did IISResets everywhere, restarted SQL Instances and nothing seemed to work.

There were no deadlocks in the database.

After several google searched we came to this link:

Talking with our DBAs we also noticed that the stats are updated daily, but according to this KB Article, some things might not execute at all on the maintenance plan.

Our last effort was the recompile:

USE SP2013_Content_DB  
sp_recompile proc_getwebnavstruct  

After that was executed everything went back to normal.

So there are probably hundreds of solution to Sharepoint being slow, this is another one that tooks us a while to figure out and you guys should be aware of.