Skip to main content
All CollectionsSupport
Slow endpoint response time: guide to troubleshooting
Slow endpoint response time: guide to troubleshooting

A common question we see is "How can I decrease my API/ background task response time" or "Why is my function stack taking so long to run"

Xano Support avatar
Written by Xano Support
Updated over a week ago

A common question we receive is "How can I decrease my API response time" or "Why is my API taking so long to run".

We understand you have the need for speed, so hopefully this self-troubleshooting guide comes in handy.

Summary

  1. Identify parts of your function stack that take a long time to run using run & debug

  2. Reduce or lean down your loops

    1. Try and replace conditionals with a GET filter or Conditional Set filters`

  3. Look into the Stream return type with Query All Records - which is memory-efficient looping

1. Identify parts of your function stack that take a long time to run using run & debug

Running & debugging an endpoint or a background task allows you to see the time it takes to call a response, but did you know Xano also shows the time it takes to run through each function within the function stack?

This is useful for identifying which function requires the most effort to run and provides a great starting point for attempting to rethink the function and opportunities to act on your data more efficiently.

2. Reduce or lean down your loops

We've noticed loops are often the most demanding in a function stack as they work through each item in a defined list and perform an action before proceeding to the next item.

Some questions to ask yourself when looking at creating a more efficient loop:

  • a. Can I run my loop on a smaller list (eg. if you're looking to identify items to remove, is it more efficient to identify items you'd like to keep?)?

  • b. Is it possible to combine multiple loops into one?

3. Try and replace conditionals with a GET filter or Conditional Set filters

Possibly you are working with a field that is sometimes present and sometimes not. Defining a default value with the GET filter allows your function stack to continue to run and complete the logic you are performing.

Conditional Set filters are helpful if you want to update only certain fields in a given database record or object.

4. Look into the Stream return type with Query All Records - which is memory-efficient looping

Stream is a new return type of Query All Records that is used exclusively with For Each Loop. Stream retrieves database records in a memory-friendly way to be used in your For Each Loop. This feature is especially useful when using large datasets that would normally require recursive function stacks.

Hopefully, these tips are helpful! Happy troubleshooting!

Did this answer your question?