WordPress REST API first call always slow


Staff member
I am analyzing/troubleshooting a custom WordPress plugin that was developed for one client that implements a REST API to be used with a 3rd party provider. One of the requirements is to have all API calls executed in less than 1 second.
Currently the plugin offers registers 2 routes: "get user" and "create user". For the sake to make this question simple, I will focus on the first route as it is the simpler one.
The average execution time for "get user" is around ~0.5 seconds BUT the first call takes always more time up to 5 seconds. All further calls are always in the ~0.5 seconds range. If the API is not used for around 1 minute, then the next first call is again taking up to 5 seconds to be completed.
This makes me believe that there is some sort of cache available for a limited period of time (~1 second) or, that the hosting (SiteGround) / database has a sleep policy but I was not able to confirm it. To find it out, I did create a custom plain PHP script that mimics the same functionality as "get user" and the average response is ~0.15 seconds BUT also the first call takes more than the average: ~0.6 seconds.
The custom script could be one possible solution for our case but we would like to first to exhaust all the possibilities to make the WordPress plugin + REST API to work in less than 1 second if possible.
<li>It seems that when using the REST API, a bunch of WP files are loaded according to this <a href="https://deliciousbrains.com/comparing-wordpress-rest-api-performance-admin-ajax-php/" rel="nofollow noreferrer">blog</a> from 2016. Does this still apply nowadays for WordPress 5.5?</li>
<li>What could be the exact reason for the first call to take more time? And how I can optimize it for further calls?</li>