Most performant way of fetching remote API data?

The most performant way of fetching remote API data is not fetching it at all. Thus, use Transients API or WP Object Cache to save your computed results for future use and avoid calling external API (and further computations) on every subsequent request. Additionally, fetching, invalidating and regeneration of this data can be done in the background, but that’s more of an advanced technique and will heavily depend on your current architecture and specific use case.

The 50ms vs 500ms difference comes from:

  • connecting to your own ajax endpoint
  • loading and executing part of WordPress engine
  • connecting, sending the request to external API endpoint and getting the response back (that 50ms, more or less)
  • parsing the response
  • your custom computational logic

Most time is spent on the first 3 steps, not the last 2. You can profile your code to see the full picture.