Query Cost Difference / Call Overhead

I have been wondering if there is any difference between these two methods...

  1. Define actions in a query, with a nice name, and apply it like this:
    image

  2. Put the code directly into the code box like this:
    image

Do they "cost" the same, or does doing #1 incur one extra call/request? Are there any optimizations to one way or the other?

@khill-fbmc I checked with a couple engineers internally who focus on performance optimization and their sense is that it shouldn't matter which way you configure the query in terms of performance overhead. Hope this helps - I know this isn't a super ground-breaking answer :upside_down_face:

If when monitoring app performance with the Debug console (great post on the feature if folks haven't checked it out) you do see differences, that could guide your decision making around how to set things up.

One thing to note - those event handlers run concurrently, so if a specific order of operations is necessary for actions that run on the same event, coordinating that timing in a script or via chained event handlers is the way to go. It's a common thing we see where folks building in Retool might put 2 -3 event handlers on a component for the same event and expect they'd run in the order that they are listed in the UI, but not necessarily!

6 Likes

Thank you for taking the time to find an answer. That is a great answer! I like knowing that I can refactor "hidden" scripts out of the component into the sidebar for easier editing and visibility and it doesn't incur an additional "query"

I was thinking that putting the "script" in the component itself, made it part of it, so that it called as part of it. The more I think about it now, it's akin to an anonymous function vs a named function. Either way they are going to be called and ran with the same "cost" :slight_smile:

Makes sense!

2 Likes