Is ":count = 0" faster, or ":first item is empty"?

When searching to make sure if an item already exists, is it faster to do the search and check to see if the count is 0, or is it faster to get the “first item” and see if that item is empty?

My guess is they’re the same but I would just create two text elements on the screen, one has count = 0 and one has first item and see which one appears first

1 Like

Check this topic, first item seems to be the way to go.

This is the Keith’s motivation:

My experience is that such conditions ARE faster than :count. I believe that, the way Bubble works, if you have a condition that is testing for that state, that state will evaluate to true as soon as the list being tested reaches the non-empty state. (That is, if you are evaluating :count, bubble must wait until the entire search or filter or whatever is done to establish the count. But if you’re just checking for non-zero list length it does not have to do that – as non-zero list length is established as soon as any item populates to the list.).

JohnMark actually tested it (see one of the last post in the topic mentioned above) and came to the same conclusion.

The topic is old and a lot has changed so the best thing to do might be to just test it yourself. Creating 10000 records should not be hard. Create a couple of records yourself, use a button with copy list and it will go pretty fast, otherwise use a backend workflow.

2 Likes

Keith provides the definitive answer over here: Is "first item is not empty" faster than "count > 0"? - #11 by keith

:count is faster

but much more expensive :slight_smile:

Dangit. And I see NickC confirming that it’s a bug which they were planning on fixing 6 months ago. So this may already be fixed or could be fixed some time soon, meaning there is still not a definitive answer here.

NickG promised to look into the bug with search:count is 0 that consumes enormous amount of WUs (12.28)
To avoid this you can use search:count < 1 and it will cost you just 0.2 WU
And search: first item is empty will cost = 2.24 WU

So search:count < 1 is 11x cheaper than search: first item is empty :slight_smile:

1 Like