[jboss-user] [JBoss Seam] - Re: JBoss EL performance vs Sun EL

mgrouch do-not-reply at jboss.com
Sat Sep 15 20:34:08 EDT 2007


Here is a piece of code to show what I'm trying to say.
In JSF EL same getters are called using reflections over and over again quite usually. So few reflection API calls could be spared and called once only.


import java.lang.reflect.Method;
  | 
  | public class ReflectionTest {
  | 
  | 	private String myProp = "VALUE";
  |     Class[] argTypes = new Class[] { };
  |     Object[] arg = new Object[0];
  |     Method getterMethod;
  | 
  |     public Object getBeanProperty(Object bean, String propName) throws Exception {
  | 		Class clazz = bean.getClass();
  | 		String getterName = "get" + Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
  | 	    getterMethod = clazz.getDeclaredMethod(getterName, argTypes);
  | 	    Object obj = getterMethod.invoke(bean, arg);
  | 	    return obj;
  | 	}
  | 
  | 	public Object getBeanPropertyViaCachedMethod(Object bean, String propName) throws Exception {
  | 	    Object obj = getterMethod.invoke(bean, arg);
  | 	    return obj;
  | 	}
  | 	
  | 	public String getMyProp() {
  | 		return myProp;
  | 	}
  | 
  | 	public static void main(String... args) throws Exception {
  | 		
  | 		ReflectionTest testBean = new ReflectionTest();
  | 		
  | 		final int ITERATIONS = 1000000;
  | 		
  | 		long start = System.currentTimeMillis();
  | 		for (int i = 0; i < ITERATIONS; i++) {
  | 			String str = (String) testBean.getBeanProperty(testBean, "myProp");
  | 			//System.out.println(str);
  | 		}
  | 		long finish = System.currentTimeMillis();
  | 		System.out.println("Run1 time=" + (finish-start) + "ms");
  | 		
  | 		start = System.currentTimeMillis();
  | 		for (int i = 0; i < ITERATIONS; i++) {
  | 			String str = (String) testBean.getBeanPropertyViaCachedMethod(testBean, "myProp");
  | 			//System.out.println(str);
  | 		}
  | 		finish = System.currentTimeMillis();
  | 		System.out.println("Run2 time=" + (finish-start) + "ms");
  | 	}
  | }
  | 

Outputs (on my PC)

Run1 time=2906ms
Run2 time=140ms


Now more or less realistic example:

Render table 1000 rows 10 columns each cell has a dropdown of 100 elements

That's a million reflection calls



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4084787#4084787

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4084787



More information about the jboss-user mailing list