GeezerVison is showing github.com — [java] Deprecate rule SimplifyStartsWith · Issue #2740 · pmd/pmd
[java] Deprecate rule SimplifyStartsWith #2740Labels is:deprecationThe main focus is deprecating public APIs or rules, eg to make them internal, or removing them Activityoowekyala commented on Dec 15, 2020 I wrote a small benchmark for that, and it appears there is a slight difference in performance, but no earlier than jdk 15:
https://github.com/oowekyala/pmd-jmh/blob/a045b6ef3337858d7541f41b19e34895d64a0286/src/main/java/net/sourceforge/pmd/MyBenchmark.java#L62-L91
Regardless, I don't think PMD should recommend micro-optimisations like this, especially when they decrease readability.
Edit: actually I wouldn't trust at all the jdk 15 result. I didn't notice JMH does not support that vm so the result may be completely wrong. I've observed absurd measurements with the same vm on other benchmarks.
Ignoring this JDK 15 benchmark, we can probably conclude that it's actually slightly faster to use startsWith with a string (possibly because of the lack of branch), and so since at least jdk 8 - which is still the most used java version. Which means the rule should be removed. adangel commented on Jan 7, 2021 Thanks for looking into this.
Regardless, I don't think PMD should recommend micro-optimisations like this, especially when they decrease readability.
I fully agree. These micro-optimisations should be left to the JVM.
I change the title of the issue to deprecate the rule and then we can remove it with PMD 7. changed the title [-][java] Is SimplifyStartsWith still relevant?[/-] [+][java] Deprecate rule SimplifyStartsWith[/+] on Jan 7, 2021added is:deprecationThe main focus is deprecating public APIs or rules, eg to make them internal, or removing them and removed a:questionRequest for information that doesn't necessarily entail changes to the code base on Jan 7, 2021added a commit that references this issue on Jan 18, 2021This issue will close once commit 9fe90d4 is merged into the 'main' branch.9fe90d4
MetadataMetadatais:deprecationThe main focus is deprecating public APIs or rules, eg to make them internal, or removing them DevelopmentNo branches or pull requestsIssue actions
|