Skip to content

[java] Improve symboltable performance - #117

Merged
adangel merged 7 commits into
pmd:masterfrom
jsotuyod:faster-symbol
Oct 30, 2016
Merged

adangel merged 7 commits into
pmd:masterfrom
jsotuyod:faster-symbol

Conversation

@jsotuyod

Copy link
Copy Markdown
Member

These changes alone have improved symboltable times reported using -b flag when analyzing the whole PMD sourcecode in ~20%.

Changes were confirmed with jvisualvm profiler too.

 - Notice the `couldResolve` doesn't guarantee a positive resolution, but still
     manages to kill early some resolver checks
 - `PrimiiveTypeResolver.resolve()` and `VoidTypeResolver.resolve()`
     were the 2nd and 5th most time consuming methods on several profiles
     I ran. This change fixes it.
 - Make use of our Java knowledge when analyzing Java code
 - Expand hashCode calculation for `MethodNameDeclaration` to avoid collisions
    when overloading.
 - Also make sure `builtInMethodDeclaration` provides a complete syntax tree to avoid NPE
    when calling `hashCode` or `equals`
@jsotuyod

Copy link
Copy Markdown
Member Author

Just added an extra commit to this changeset. Though it's standalone, it's closely related. The change is two-fold:

  • fix ClassScope's generation of the phony valueOf method on enums to avoid NPEs when calling equals / hashCode on the MethodNameDeclaration
  • expand MethodNameDeclaration.hashCode to take into account the types of the arguments besides the amount to reduce the number of collisions on the HashMap when using overloading (ie: all the visitors on the PMD source!)

This reduces the time needed to analyze the PMD sourceset a further 10% on top of the original 20%.

I provide a sample run for reference on my machine (I run it inside a for for local benchmarking):

Baseline (clean from master):

time pmd-dist/target/pmd-bin-baseline/bin/run.sh pmd -threads 0 -d ./ -b -f text -R java-braces > /dev/null

--------------------------------<<< Summary >>>--------------------------------
Segment Time (secs)

Collect files: 0.236
Load rules: 0.117
Parser: 6.894
Symbol table: 53.821
RuleChain visit: 0.250
Reporting: 0.052
Rule total: 0.000
Rule chain rule total: 0.000
Rule Average (0 rules): 0.000
RuleChain Average (4 rules): 0.211

-----------------------------<<< Final Summary >>>-----------------------------
Total Time (secs)

Measured total: 62.212
Non-measured total: 1.023
Total PMD: 63.236

real 1m3.666s
user 1m45.272s
sys 0m0.656s

This changeset:

time pmd-dist/target/pmd-bin-5.2.2-SNAPSHOT/bin/run.sh pmd -threads 0 -d ./ -b -f text -R java-braces > /dev/null

--------------------------------<<< Summary >>>--------------------------------
Segment Time (secs)

Collect files: 0.192
Load rules: 0.060
Parser: 6.287
Symbol table: 36.542
RuleChain visit: 0.272
Reporting: 0.046
Rule total: 0.000
Rule chain rule total: 0.000
Rule Average (0 rules): 0.000
RuleChain Average (4 rules): 0.197

-----------------------------<<< Final Summary >>>-----------------------------
Total Time (secs)

Measured total: 44.188
Non-measured total: 0.540
Total PMD: 44.728

real 0m44.866s
user 1m24.720s
sys 0m0.592s

 - We can tell if a name can be resolved or not, and we can do so in
    constant time.
@jsotuyod

Copy link
Copy Markdown
Member Author

Just realized I could rework ExplicitImportResolver along with the other changes in this branch and make it orders of magnitude faster (which is meaningful, since this is the first resolver hit after primitives / void). This shaved another 6 seconds from my runs:

--------------------------------<<< Summary >>>--------------------------------
Segment                                         Time (secs)

Collect files:                                        0.216
Load rules:                                           0.058
Parser:                                               6.716
Symbol table:                                        30.871
RuleChain visit:                                      0.245
Reporting:                                            0.050
Rule total:                                           0.000
Rule chain rule total:                                0.000
Rule Average (0 rules):                               0.000
RuleChain Average (4 rules):                          0.200

-----------------------------<<< Final Summary >>>-----------------------------
Total                                           Time (secs)

Measured total:                                      38.954
Non-measured total:                                   0.584
Total PMD:                                           39.538

real    0m39.669s
user    1m19.440s
sys 0m0.600s

 - Classes in java.lang.* aren't that many, yet they hit a lot (String,
    all boxed primitives, Math, etc.), so it makes sense to cache them
@jsotuyod

Copy link
Copy Markdown
Member Author

I figured out I could actually fully implement couldResolve in a mucha saner way, it flies now:

This PR now makes symboltable resolution 322% faster than before. I'll stop touching this PR while it's still readable / small enough for a proper review. Hopefully during the weekend all this will be merged / I'll get feedback and it will be much easier to keep on pushing performance.

--------------------------------<<< Summary >>>--------------------------------
Segment                                         Time (secs)

Collect files:                                        0.241
Load rules:                                           0.053
Parser:                                               6.216
Symbol table:                                        16.711
RuleChain visit:                                      0.290
Reporting:                                            0.055
Rule total:                                           0.000
Rule chain rule total:                                0.000
Rule Average (0 rules):                               0.000
RuleChain Average (4 rules):                          0.216

-----------------------------<<< Final Summary >>>-----------------------------
Total                                           Time (secs)

Measured total:                                      24.432
Non-measured total:                                   0.547
Total PMD:                                           24.979

 - Typos, extra whitespace, a missing static, clearer loops..
@adangel adangel changed the title Improve symboltable performance [java] Improve symboltable performance Oct 30, 2016
@adangel
adangel merged commit 9b7372e into pmd:master Oct 30, 2016
@jsotuyod
jsotuyod deleted the faster-symbol branch October 30, 2016 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants