12 Replies Latest reply on Nov 14, 2008 3:46 PM by scheintod

    more foreach stuff - performance

    scheintod

      Hello again,


      since foreach now (nearly) works as expected there is another issue which trouble me:


      Following code:


      <c:forEach items="handler.getList()" var="item">
      
         #{item.title}
         #{item.teaser}
         #{item.xyz}
         ...
      </c:forEach>
      



      results in multiple calls to handler.getList(). In this example these are: handler.getList()...getTitle(), handler.getList()...getTeaser(), hander.getList()...getXyz()


      I guess ... stands for some index access to the list ( get(0), get(1), get(2), etc.).


      The resulting amount of calls to handler.getList() is therefore the number of list entries x number of accesses to an list member.


      In my case this are about 50x40 equals 2000 per page. Which in turn means 2000 in-/outjection circles, list accesses, method calls, etc.


      What makes that even worse is that my getList() method generates the list depending on context variables every time the method is called.


      I could implement some kind of caching. But it would be better, if there was some way of simply reducing this mess to only one call.


      I've tried using c:set but with no change in behaviour.


      Does anyone have a solution for that?


      Thank you very much.

        • 1. Re: more foreach stuff - performance
          dhinojosa

          Just, curious, were you averse to using the facelet ui:repeat tags?

          • 2. Re: more foreach stuff - performance
            scheintod

            NO! Not at all.


            My first version had ui:repeat. Didn't work.


            The very core of the project is an extremely detailed template system which allows to determine for each and every object which template to use depending on class and many parameters.


            So for every item in a list I have to choose another template to render that spezific object. Looks like


            <c:foreach items="handler.getList()" var="item">
            
              <ui:include src="item.template()">
                 <ui:param name="item" value="#{item}"/>
              </>
            </>
            


            As I learnd (the hard way) ui:include doesn't work ui:repeat but only with c:forEach.


            • 3. Re: more foreach stuff - performance
              dustismo

              Not an answer to your forEach problem (though I think creating your list in a getter is generally bad form) -- but I believe icefaces has a dynamic include tag.  I have also seen that a couple of other people have been working on one (IMHO should be a basic facelets tag).


              Let me know if find something better then the icefaces one.


              -Dustin

              • 4. Re: more foreach stuff - performance
                dhinojosa

                Hmmm


                <c:foreach items="handler.getList()" var="item">
                
                  <ui:include src="item.template()">
                     <ui:param name="item" value="#{item}"/>
                  </>
                </>
                



                That code is strange to me, especially with parenthesis.


                <c:foreach items="#{handler.list}" var="item">
                  <ui:include src="#{item.template}">
                     <ui:param name="item" value="#{item}"/>
                  </ui:include>
                </c:foreach>
                


                Is there any reason why the above wouldn't work?

                • 5. Re: more foreach stuff - performance
                  scheintod

                  sorry. It was pretty late and I was to lazy to write the full closing tags.


                  Changing #{handler.getList()} to #{handler.list} doesn't make any differences. Both result in handler.getList().get( i ).getXyz() code.

                  • 6. Re: more foreach stuff - performance
                    scheintod

                    Hi


                    I cant even find the icefaces one.


                    http://www.icesoft.com/developer_guides/icefaces/tld/index.html


                    In icefaces tutorial I only find references to ui:include which is servlets.


                    Meanwhile I changed my handler from @Stateless to EVENT scope. This way I can cache the generated List. This reduces the complete runtime from 10s to 2s. But event this is at least 20x to slow to use in production.


                    Considering the generated code which would look like


                    handler.getNavigation().get(0).getA()
                    ...
                    handler.getNavigation().get(0).getZ()
                    handler.getNavigation().get(1).getA()
                    ...
                    handler.getNavigation().get(100).getZ()
                    



                    I even tried changing the List from LinkedList to ArrayList to give it better indexed performance but with little to no effect.


                    Since there isn't anything else I can blame, I suspect the
                    getNavigation() to be the problem because it requires seam the complete seam bijection processing before and after invocation which could slow it down so much.


                    The bad here is that there is really no need for the getNavigation to be called a few thousand times. What I'm looking for simply a way to have a iterator-tag-thingy which only fetches its list one time.

                    • 7. Re: more foreach stuff - performance
                      dustismo

                      Looks like icefaces overrides the regular ui:include tag..


                      http://facestutorials.icefaces.org/tutorial/dynamic-includes-tutorial.html



                      -Dustin

                      • 8. Re: more foreach stuff - performance
                        scheintod

                        I see no indication for that after reading that page.


                        The example uses ui:include like any other application. The dynamic behaviour here is the same as with any other ui:include calls and no ui:repeat is used. (Let alone the title: How to use Facelets dynamic include)

                        • 9. Re: more foreach stuff - performance
                          pmuir

                          Florian Bantner wrote on Apr 05, 2008 01:23 AM:


                          But it would be better, if there was some way of simply reducing this mess to only one call.



                          There is none I know of. I suggest outjecting the result of handler.getList() to the event context, and then referring to the outjected variable on the page. In that way you avoid the overhead of interceptors, bijection etc.

                          • 10. Re: more foreach stuff - performance
                            scheintod

                            Hi Pete,


                            thanks for the reply. That's what I've done by now in order to get it to run at least at clickable speed. But I am still looking for a better solution since for comming versions I have to build something like


                            <c:forEach items="handler.getMenu( 'title' )" var="item">
                              do stuff
                            </c:forEach>
                            



                            and I have no idea how I would do that with outjection.


                            Best regards

                            • 11. Re: more foreach stuff - performance
                              visumagic

                              hi Florian ,
                              Are you able to implement forEach, im facing serious problem here , is this a bug in seam.
                              While using iterators c:forLoop,ui:repeat,on list type variables in seam context, the indexing variable's properties are not available inside the loop.


                              example:


                              <ui:repeat value="#{CollegeProfile.collegeCourses}" var="coursei">
                              <s:label title="${coursei.title}"></s:label>
                              </ui:repeat>




                              thanks
                              raghu

                              • 12. Re: more foreach stuff - performance
                                scheintod

                                Hi Raghu,


                                sorry. My problem was once and for all solved by not using ejb at all.


                                Regards,


                                Florian