apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.5k stars 26.43k forks source link

Method invokes inefficient Number constructor #1245

Closed hqq2023623 closed 6 years ago

hqq2023623 commented 6 years ago

JavaDeserializer#getParamArg

1

for values that between -128 ~ 127 , autoboxing or call valueOf() is more efficient than using consctrutor , and use less memory .

reference blog : http://blog.csdn.net/qq_27093465/article/details/52473649

ways to change : change to autoboxing or Xxx.valueOf(0);

below is the change :

protected static Object getParamArg(Class cl) {
    if (!cl.isPrimitive())
        return null;
    else if (boolean.class.equals(cl))
        return Boolean.FALSE;
    else if (byte.class.equals(cl))
        return 0;
    else if (short.class.equals(cl))
        return 0;
    else if (char.class.equals(cl))
        return 0;
    else if (int.class.equals(cl))
        return 0;
    else if (long.class.equals(cl))
        return 0L;
    else if (float.class.equals(cl))
        return 0F;
    else if (double.class.equals(cl))
        return 0D;
    else
        throw new UnsupportedOperationException();
}
chickenlj commented 6 years ago

Can you please create a PR?

zonghaishang commented 6 years ago

How to creat patch file ?

zonghaishang commented 6 years ago

How to create patch files ?

chickenlj commented 6 years ago

Sorry, this change seems to have some problems. Refer your PR #1375 for more details