Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Optimize UI Performance with Flags and Set Analysis

In my prior work as a developer and in talking with my Qlik peers there is agreement that creating binary flags in the script (to assist in identifying key segments) is best practice.  Anytime you can pre-process data in the script, the UI will perform faster and have less work to do.


Less widely understood is what to do in the UI once the flags have been created.  How should these flags be used in expressions?  Which approach yields the best performance?  One valid typical approach uses set analysis in the following manner to sum Sales where the flag is true:


=sum({$<ScriptFlag = {1}>} SalesAmount)


However, this approach still requires the UI to conditionally evaluate a true/false comparison.  From a performance standpoint (important with big data) there is an alternate approach I recommend - special thanks to Kris Balow (@KrisBalow) from Grange Insurance for suggesting this:


When leveraging binary flags (0,1) from the script, simple multiplication of the (flag * metric) performs much faster in the application UI.  In my testing, both methods appear to return valid results.

This concept may not work with all aggregate functions, but sum, avg, and count are compatible.  Just think about the math before you do it.  It’s faster than set analysis because there is no conditional evaluation involved.  It’s a simple straight calculation across all records. 

Recently I saw a 70% improvement in response time in a customer application by making this simple shift. Using set analysis the response time between clicks was 4-6 seconds. Using straight multiplication it dropped to 1-2 seconds.  In this case, a pretty big deal for the users who were making 500+ selections a day.  As always, performance lifts will depend on the application. 

=sum(ScriptFlag * SalesAmount) – performs much faster


Questions:


- What performance lift do you get?

- What limitations do you see with this approach?

Regards,

Kyle

14 Replies
hic
Former Employee
Former Employee

I have just like you also made some test and compared the different cases. I will write a blog post about the results, but I can already now say the following:

There is some overhead with Set Analysis that multiplication doesn't have, and as a consequence multiplication outperforms Set Analysis in small data sets (~1M rec). But if the data set becomes larger, Set Analysis outperforms multiplication.

Hence, in the cases where you need performance, Set Analysis is the best choice.

HIC

rbecher
MVP
MVP

Dear Henric,

thanks for clarification. The next question to me would be if this two-step process caching is made after parsing the expression. Because the set expression has to be parsed out of the whole expression. Hence, different spellings of the set analysis expression would have an effect or not?

- Ralf

Astrato.io Head of R&D
Not applicable
Author

Great article!

ablaas
Contributor II
Contributor II

Quite interesting... If it's done before parsing, it would make much sense to create sets in variables so they're always spelled the same (using parameters  would help in reusing these sets in different situations).

Regards

alex

ablaas
Contributor II
Contributor II

What about if we use flags defined as duals?

eg:

Load dual(text,value) as dualFlag inline [

text,value

Yes,1

No,0

];


I had to use the string comparison in the set analysis, so I had the worst scenario, as the syntax comparing the NUM value didn't work:

sum({$<dualFlag = { 1 } >} amount ); // didn't work

sum({$<dualFlag = { 'Yes' } >} amount ); // bad performance

sum(dualFlag * amount); // is this the only choice?

Regards,

Alex