Basic question about multi-query

If I need to retrieve different data independently, which one will be faster :
OPTION 1 :

//front end:
Promise.all([query1, query2, query3]).then(res => {/*code*/})

or OPTION2:

//front end:
import {retrieveData} from 'backend/queries.jsw';
retrieveData([query1, query2, query3]).then(res => {/*code*/});

//backend:
export function retrieveData(queries){
return Promise.all(queries);
}

What do you think?

Do you realize that difficult questions like this give me a headache? Do you care? I thought we were friends.

I suspect that performing all of the queries in the backend will be faster. Frontend queries have a built-in mechanism which sort of automagically turns them into calls to backend functions. By doing all three in the backend, you save yourself the overhead of the frontend to backend mechanism.

If I’m optimizing a site, I generally rely on backend queries as it’s a more direct interface. For just one query it might not matter, but for multiple queries backend should be more efficient.

BTW - backend queries have a big advantage in that they’re more secure. Sensitive data that’s part of the query is hidden from site visitors. In a backend function. you can return only the data that’s meant to be viewed by your site visitors.

And of course, you can always contact the Wix support team who might be able to get a more accurate answer from some smart Wix devs, who will tell you that I’m delusional.

@yisrael-wix , Thanks. and sorry for the headache :blush:.
(Yes, I thought it might be faster as it’s a single call to the back end, but on the other hand, since these back and forth calls are run asynchronously, it may not be so significant. And I don’t know what’s the cost of the additional import in the second option).
Anyway, thanks for the answer, I’ll try to see if it improves the performance on my site.

@jonatandor35 You can add console.log() statements with time stamps and get the elapsed time for each type of call.

Of course, you realize that we now expect for you to suppy a full report on performance statistics - fancy graphs and charts, and spreadsheets full of hard to understand statistical calculations.

@yisrael-wix :blush: