I filed this bug after seeing it in startup profiles, where isEmpty() avoids an instanceof and four(!) method calls, so getting rid of a few of these has a measurable impact on startup. It seemed prudent to just replace it all while we're at it.

C2 should be able to optimize equals("") to the equivalent of isEmpty() for hot cases, of course, but those JIT threads are probably better spent optimizing other things. :-)

/Claes

On 2018-12-06 21:27, Jim Laskey wrote
I assume you automated this change, might be worthwhile to automate a 
verification (compare the -+ pairs.) Eyeballing the patch it seems complete, 
one comment changed as well.

Question: Is it probably that vm optimizes .equals(“”) to .isEmpty() and there 
is no net win, ie., more of an esthetic clean up than for performance?

Cheers,

— Jim



On Dec 6, 2018, at 4:04 PM, Roger Riggs <roger.ri...@oracle.com> wrote:

Please review changing string.equals("") to string.isEmpty().
isEmpty is preferred, performs better and is easier to optimize.

The change is a literal substitution in all files and only in these modules:

   java.base
   java.logging
   java.management
   java.management.rmi
   java.naming
   java.net.http
   java.prefs
   java.rmi
   java.scripting
   java.sql
   java.sql.rowset
   java.xml
   jdk.jartool
   jdk.javadoc
   jdk.jcmd
   jdk.jconsole
   jdk.management.agent
   jdk.naming.dns
   jdk.rmic


Webrev:
http://cr.openjdk.java.net/~rriggs/webrev-string-isempty-8214971-1/

Issue:
   https://bugs.openjdk.java.net/browse/JDK-8214971

Thanks, Roger

Reply via email to