Skip to main content
March 24, 2021
Question

What is the most efficient between IF and showWhen=False ?

  • March 24, 2021
  • 6 replies
  • 0 views

Hi,

My question is maybe a little naive but for increasing performance I was asking myself if use the showWhen attribute on 10 components is as good using an IF condition to masking all these components.

I took 3 examples :

1/ Case showWhen on all components :

ColumnsLayout(
    columnLayout
        TextField_1label: "1", showWhen: false)
    columnLayout(
        TextField_2(label: "2", showWhen: false)

    ...

    columnLayout(
         TextField_10(label: "10", showWhen: false)
)

2/ Case showWhen on layout component :

ColumnsLayout(
    columnLayout
        TextField_1(label: "1")

    columnLayout(
        TextField_2(label: "2")
    ...

    columnLayout(
        TextField_10(label: "10")
    ),
    showWhen : false
)

3/ Case with an IF condition :

local!value: false,
if(local!value,
   ColumnsLayout(
      columnLayout
          TextField_1(label: "1")

      columnLayout(
          TextField_2(label: "2")
      ...

      columnLayout(
          TextField_10(label: "10")
     )
  ),
  {}
)

Is the 3/ more efficient as Appian do not need to load anything ?  

6 replies

stefanhelzle0001
March 24, 2021

AFAIK this will not have any significant impact on performance. I try to create readable code. And putting showwhens into a larger number of components is not readable/understandable.

I created by own component which just takes a number of components and a showWhen. It does nothing else then showing/hiding a bunch of components. Works pretty well in cases where I do not want to add any layout or section.

March 24, 2021

so Stefan you confirm, (leaving the readable aspect left aside) that the 1/ and 2/ cases (showwhen) are as much as efficient than the case 3/ (using the IF) ? 

stefanhelzle0001
March 24, 2021

This is what I experienced in the past. Yes.

When doing Performance optimizations, I pick the big candidates first. Most of the time these are issues in DB access or slow web services.

davel001150
March 24, 2021

Premature optimization is the root of all evil.  I just use showWhen quite extensively.  I did find one case, however, where showWhen didn't behave as I intended, but if condition worked quite well.  I think there can be a difference between when a component and related code is hidden from the user, and when the if returns false so absolutely NONE of the associated code even runs.

Unless you need to if(), a good example is when the component doesn't have a showWhen, I would use showWhen.  It probably is the tiniest bit better, and certainly more maintainable, or Appian wouldn't have bothered inventing it.

March 24, 2021

Thanks a lot David for your reply