Posted on

Debugging slow searches

Reasonable expectations for Relevanssi searching speeds are measured in seconds. Relevanssi does not generally return results in milliseconds. On the other hand, the searches shouldn’t take more than few seconds in most cases. Multisite searches are a different thing: even if the searching is reasonably fast, searching across many sites will always be slow. Doing one-second searches across ten sites will take ten seconds.

Use Query Monitor. When a search is slow, the first step is to figure out where the time is spent. Query Monitor is a must-have tool here.

Query Monitor output in the admin bar, showing page generation time, memory spent, database time spent and number of queries.

Query Monitor output is marked with the red border. The output includes the page generation time (0.43s), peak memory use (8,452kB), number of database time spent (0.0217s) and the number of database queries (50 queries). This is a good place to start.

Slow queries. The time spent doing database queries should be less than 0.1 seconds. If it’s over one second, it’s time to dig in to the slow queries to see what those are. Query Monitor will show you which are the slow queries and how much time they take.

Too many queries. The problem may also be the number of queries. Typically the number of queries made should be close to the number of posts found. If there’s a big difference, that’s often a performance problem. If your site does 3000 queries every time you search, that’s going to take time even if those queries are fast. (See Performance issues here for avoiding common pitfalls.)

Meta query filtering. Custom field filtering or meta queries can make the database queries slow; it’s one of the slowest things you can do with WordPress. Usually, it’s fine, but sometimes it can be a big problem. It’s possible to move custom field filtering outside the database query, and sometimes it’s more effective that way. The same goes with complex taxonomy queries, but those are usually much faster than meta queries.

Slow excerpts. If the database queries are fast, but the search is still slow, the problem is somewhere else. A good first step is to see if building excerpts is slow. Try disabling custom excerpts in Relevanssi and see if that helps. Building excerpts can sometimes be the slowest part of the search, especially if your posts are very long (book length documents, for example). Sometimes disabling custom excerpts is the best solution, sometimes ofter performance optimizations can be done.

Something else. If the problem is not the database queries and not the excerpts, then figuring out the reason requires additional debugging and adding timers to your search results templates to see where the PHP process takes the time. If you have profiling tools available, those are very helpful, but usually that’s not an option.

We can help you! Relevanssi Premium support is there for you if you have performance problems. If you don’t have Relevanssi Premium, you can contact us on WordPress.org support forums. If you take these steps to investigate where the search is slow that will make solving your problem much faster.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published. Required fields are marked *