Uniface User Forum

 View Only
  • 1.  performance issue while fieldproperties+BackColor

    Posted 06-24-2021 15:41

    Hi,

    I am new to uniface tech. I came across a performance issue in a uniface screen which has Select All button which when clicked by user it will color all the records with grey color to indicate they are selected (just like excel) but it takes more that 5mins to color all the records (10,000 records) with each record having 12 fields. Below is code snippet request you to suggest how performance can be improved.

    l_curocc = $curocc (entity_nm)
    l_totdbocc = $totocc(entity_nm)

    l_tot_flds = $itemcount(l_fieldnames)
    setocc "entity_nm", 1
    repeat

    l_cnt = 1
                while (l_cnt <= l_tot_flds)

                getitem(l_fieldname, l_fieldnames, l_cnt)

                scan l_fieldname, "PBTN"

                if ($result <= 0)

                             l_frac = $frac ($curocc(l_entity) / 2)

                    if (l_frac = 0)

                        $fieldproperties (l_fieldname) = "BackColor=%%l_rowselectdark"

                        l_color = l_rowselectdark

                    else

                       $fieldproperties (l_fieldname) = "BackColor=%%l_rowselectlight"

                        l_color = l_rowselectlight

                    endif

                endif

                l_cnt = l_cnt + 1

            endwhile            if (l_curocc < l_totdbocc)
                    setocc "entity_nm", $curocc (entity_nm) + 1
                endif;
            until ($status < 0 | l_curocc >= l_totdbocc)
            setocc "entity_nm", l_curocc


    Thanks,

    Imran.



  • 2.  RE: performance issue while fieldproperties+BackColor

    Posted 06-24-2021 16:52

    Hi Imran,

    Have you tried to use

    $entityproperties("yourEnt") = "backcolor=gray"

    or

    $curentpropertties("yourEnt") = "backcolod=gray"

    instead?

    Regards,

    Knut



  • 3.  RE: performance issue while fieldproperties+BackColor

    PARTNER
    Posted 06-24-2021 16:57

    Wouldn't it have to be $occproperties in order to get the two-tone stripes that his original calls for? 

    He doesn't mention if this is a grid widget, where neither $entityproperties nor $occproperties would work.

    Also, both of those would colour up the bits between the fields, not the field backgrounds themselves yes/no? 


    Regards, 


    Iain



  • 4.  RE: performance issue while fieldproperties+BackColor

    Posted 06-25-2021 04:53

    Also, both of those would colour up the bits between the fields, not the field backgrounds themselves - yes 

    Hi,

    Thanks for your feedback.

    Iain is correct entityproperties changes the color of grid and not field background hence this does not work. currentproperties does not work at all. 


    attached a screenshot of how the grid looks currently. Please let me know if anyother possible solution.


    Imran. 



  • 5.  RE: performance issue while fieldproperties+BackColor

    Posted 06-24-2021 17:15

    This is how I would do it. There's extra processing in your code just trying to determine if the field is a button. If you want to color every other occurrence, then just do that it doesn't appear like you care about anything else. If you actually care about the button color, then you can solve that another way.

    setocc "entity_nm", 1
    forentity "entity_nm"
         if ($curocc(entity_nm)% 2 = 0)
             $curentproperties(entity_nm) = "BackColor=%%l_rowselectdark"
             l_color = l_rowselectdark
         else
             $curentproperties(entity_nm) = "BackColor=%%l_rowselectlight"
             l_color = l_rowselectlight
         endif
    endfor
    setocc "entity_nm", 1



  • 6.  RE: performance issue while fieldproperties+BackColor

    Posted 06-25-2021 06:39

    Hi

    By far, the more consuming step is changing occurrence (setocc or forentity).

    Probably, you do not need to color all 10.000 occurrences at this time. And looping over the 10.000 occs will cause all of them to be read from database.

    I usually write this sort of code in trigger Format (formatToDisplay in version 10) which is executed just before the field is going to be displayed. Sometimes I use trigger read instead. The goal is to waste this time only when needed.

    $fieldname, <$fieldName>, $entname, <$entName> can be useful here.


    Regards



  • 7.  RE: performance issue while fieldproperties+BackColor

    Posted 06-25-2021 07:40

    Hi Imran,

    There are more choices but some of them are depending from what your component is enabling user to do.

    Which Uniface version are you using? This proposal is for U9 or U10.

    Going to only optimize the current code: Larry has already pointed out that there is an overhead if the field name include string "PBTN", probably buttons. I try to preserve your logic into this optimized code proposal:

    l_fieldnames = $entinfo("entity_nm", "PAINTEDFIELDS")
    l_curocc = $curocc (entity_nm)
    l_totdbocc = $totocc(entity_nm)
    l_rowselectdark = "green"
    l_rowselectlight = "white"
    forentity "entity_nm"
          forlist l_fieldname in l_fieldnames
                if ($scan(l_fieldname, "PBTN") = 0)
                      if ($curocc(l_entity)%2 = 0)
                            $fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectdark%%%"
                      else
                            $fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectlight%%%"
                      endif
                endif
          endfor
          if ($curocc(entity_nm) = l_totdbocc) break ; this is avoiding to build the whole hitlist
    endfor
    setocc "entity_nm", l_curocc

    You could also try to furtherly improve perf applying the coloring routine only:
    - from ($curocc(entity_nm) - $paintedocc(entity_nm)) when greater than zero
    - to ($curocc(entity_nm) + $paintedocc(entity_nm)) but not greater than $totocc()
    It becomes:

    l_fieldnames = $entinfo("entity_nm", "PAINTEDFIELDS")
    l_curocc = $curocc (entity_nm)
    l_totdbocc = $totocc(entity_nm)
    l_startrow = $curocc(entity_nm) - $paintedocc(entity_nm)
    if (l_startrow < 1) l_startrow = 1
    l_endrow = $curocc(entity_nm) + $paintedocc(entity_nm)
    if (l_endrow > l_totdbocc) l_endrow = l_totdbocc
    l_rowselectdark = "green"
    l_rowselectlight = "white"
    setocc "entity_nm", l_startrow
    while $status > 0
          if ($curocc(l_entity)%2 = 0)
                forlist l_fieldname in l_fieldnames
                      if ($scan(l_fieldname, "PBTN") = 0)
                            $fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectdark%%%"
                      endif
                endfor
          else
                forlist l_fieldname in l_fieldnames
                      if ($scan(l_fieldname, "PBTN") = 0)
                            $fieldproperties (l_fieldname, "BackColor") = "BackColor=%%l_rowselectdark%%%"
                      endif
                endfor
          endif
          if ($curocc(entity_nm) = l_endrow) break
          setocc "entity_nm", $curocc(entity_nm) + 1
    endwhile
    setocc "entity_nm", l_curocc

    This last example should always work quite fast (less than 2 secs) everywhere...

    Let us know if it help you.

    Regards,
    Gianni



  • 8.  RE: performance issue while fieldproperties+BackColor

    Posted 06-25-2021 12:05

    Hi Gainni,

    I was able to resolve the issue.

    The issue was due to additional logic (not part of suedo code shared above) which loops through all the records which are already selected causing performance lack. I am still working to improve performance further I will let you all know if I need any help! 

    Thank you for your time.


    Imran.