9 Replies Latest reply on Feb 7, 2013 9:05 AM by prarora803

    50% performance hit in ClonedObjectResolver.resolveCloned

    samkwitty

      We have a very simple page that displays a rich:datatable. We noticed that on the backend ClonedObjectResolver.resolveCloned gets called a lot and is very slow. Looking at the method (code below) I think the issue is that it scans the request map every time and looks for a graph prefix validator. If we comment this code out the performance improves 50%. The main question is what is it trying to do and is this only needed in some specific situations like a particular component on the page?

       

      {code}

      public static Object resolveCloned(ELContext context, Object base, Object property){

              if(null != base || null != property){

                  FacesContext facesContext = FacesContext.getCurrentInstance();

                  Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();

                  for (String key : requestMap.keySet()) {

                      if(null != key && key.startsWith(UIGraphValidator.STATE_ATTRIBUTE_PREFIX)){

                          UIGraphValidator.GraphValidatorState state = (GraphValidatorState) requestMap.get(key);

                          if(state.isSame(base, property)){

                              return state.getCloned();

                          }

                      }

                  }

              }

              return null;

          }

      {code}

        • 1. 50% performance hit in ClonedObjectResolver.resolveCloned
          samkwitty

          Actually on a moderately loaded machine it is more like 70%. So no one knows what this code is all about?

          • 2. 50% performance hit in ClonedObjectResolver.resolveCloned
            jbalunas

            Hi Sam,

             

            Thanks for debugging the issue, and letting us know.  Could you create a RichFaces jira https://issues.jboss.org/browse/RF to cover this issue and we'll review it closer.

             

            It looks like there could certainly be some optimizations here!

             

            Thanks,

            -Jay

            • 3. 50% performance hit in ClonedObjectResolver.resolveCloned
              alexsmirnov

              Good catch. I created JIRA issue for that https://issues.jboss.org/browse/RF-10987 , going to take closer look next week

              • 4. 50% performance hit in ClonedObjectResolver.resolveCloned
                samkwitty

                Great thanks for looking into this. We are experiencing this in the 3.x code line. Looking at the JIRA item it is set for the 4.x code line. Does this mean it is not going to be fixed in 3.x?

                 

                -Sam

                • 5. Re: 50% performance hit in ClonedObjectResolver.resolveCloned
                  evdelst2

                  What are the consequences if I disable this code?

                  Is it only used if (for example) a rich:graphValidator is used?

                   

                  - Edwin

                  • 6. Re: 50% performance hit in ClonedObjectResolver.resolveCloned
                    samkwitty

                    We have had it disabled ever since I posted the issue. Seems to have no impact and it runs way faster.

                    • 7. Re: 50% performance hit in ClonedObjectResolver.resolveCloned
                      prarora803

                      We seem to be facing the same issue in RichFaces 3.3.3. Since there is no patch for this defect in 3.x and we cannot upgrade to 4.x in the near future, we wanted to try out your solution of commenting out the culprit code.

                       

                      Could you please tell us exactly what part of the code did you comment out? Was it just the UIGraphValidator or the entire resolveCloned method?

                      Also, did it have any impact on the application functionality?

                       

                      Really appreciate your help!

                      • 8. Re: 50% performance hit in ClonedObjectResolver.resolveCloned
                        evdelst

                        Hi,

                         

                        I created a new class org.richfaces.component.ClonedObjectResolver.

                         

                        I haven't met any problems yet.

                         

                        Edwin

                         

                         

                        /**

                        *

                        */

                        package org.richfaces.component;

                         

                         

                        import java.beans.FeatureDescriptor;

                        import java.util.Iterator;

                         

                         

                        import javax.el.ELContext;

                        import javax.el.ELResolver;

                         

                         

                        /**

                        * @author asmirnov

                        *

                        */

                        public class ClonedObjectResolver extends ELResolver {

                         

                         

                            /* (non-Javadoc)

                             * @see javax.el.ELResolver#getCommonPropertyType(javax.el.ELContext, java.lang.Object)

                             */

                            @Override

                            public Class<?> getCommonPropertyType(ELContext context, Object base) {

                                // Do nothing

                                return null;

                            }

                         

                         

                            /* (non-Javadoc)

                             * @see javax.el.ELResolver#getFeatureDescriptors(javax.el.ELContext, java.lang.Object)

                             */

                            @Override

                            public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,

                                    Object base) {

                                // do nothing

                                return null;

                            }

                         

                         

                            /* (non-Javadoc)

                             * @see javax.el.ELResolver#getType(javax.el.ELContext, java.lang.Object, java.lang.Object)

                             */

                            @Override

                            public Class<?> getType(ELContext context, Object base, Object property) {

                                Object cloned = resolveCloned(context, base, property);

                                if(null != cloned){

                                    context.setPropertyResolved(true);

                                    return cloned.getClass();

                                }

                                return null;

                            }

                         

                         

                            /* (non-Javadoc)

                             * @see javax.el.ELResolver#getValue(javax.el.ELContext, java.lang.Object, java.lang.Object)

                             */

                            @Override

                            public Object getValue(ELContext context, Object base, Object property) {

                                Object cloned = resolveCloned(context, base, property);

                                if(null != cloned){

                                    context.setPropertyResolved(true);

                                }

                                return cloned;

                            }

                         

                         

                         

                            /* (non-Javadoc)

                             * @see javax.el.ELResolver#isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object)

                             */

                            @Override

                            public boolean isReadOnly(ELContext context, Object base, Object property) {

                                // TODO Auto-generated method stub

                                return false;

                            }

                         

                         

                            /* (non-Javadoc)

                             * @see javax.el.ELResolver#setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object)

                             */

                            @Override

                            public void setValue(ELContext context, Object base, Object property,

                                    Object value) {

                                // TODO Auto-generated method stub

                         

                         

                            }

                         

                         

                            public static Object resolveCloned(ELContext context, Object base, Object property){

                                return null;

                        //        if(null != base || null != property){

                        //            FacesContext facesContext = FacesContext.getCurrentInstance();

                        //            Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();

                        //            for (String key : requestMap.keySet()) {

                        //                if(null != key && key.startsWith(UIGraphValidator.STATE_ATTRIBUTE_PREFIX)){

                        //                    UIGraphValidator.GraphValidatorState state = (GraphValidatorState) requestMap.get(key);

                        //                    System.out.println(""+key);

                        //                    if(state.isSame(base, property)){

                        //                        return state.getCloned();

                        //                    }

                        //                }

                        //            }

                        //        }

                        //        return null;

                            }

                        }

                        • 9. Re: 50% performance hit in ClonedObjectResolver.resolveCloned
                          prarora803

                          Thank you so much Edwin! Really appreciate the help!

                           

                          -Priyanka