Skip to content

[java] Don't use ClassNotFoundException to report unresolved classes#2236

Merged
adangel merged 1 commit into
pmd:masterfrom
oowekyala:typeres-no-exceptions
Feb 16, 2020
Merged

[java] Don't use ClassNotFoundException to report unresolved classes#2236
adangel merged 1 commit into
pmd:masterfrom
oowekyala:typeres-no-exceptions

Conversation

@oowekyala

Copy link
Copy Markdown
Member

So I was fiddling with Intellij's profiler, and found out that the constructor of ClassNotFoundException slows down classloading by a huge factor. In all usages that matter, the exception is immediately caught by the caller and ignored.

With this change we return null instead. This speeds up type resolution by a factor of 2.

Here's a comparison on the sources of OpenJDK 12 (around 17700 source files):

  • Master:
17700
Resolved: 18006988, unresolved 2591866
Resolved 88.0%
Errors 5

--------------------------------------------<<< Rule >>>--------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

TypeResTest                                             2,4144           2,4144   17742

Total Rule                                              2,4144           2,4144

------------------------------------------<<< Summary  >>>------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Rule                                                    2,4265           0,0122   17742
Rulechain Rule                                          0,0065           0,0065   17742
Collect Files                                           0,1902           0,1902        1
Load Rules                                              0,0587           0,0587        1
Parser                                                 38,6618          38,6618   17743
Qualified Name Resolution                               6,5715           6,5715   17743
Symbol Table                                           25,9257          25,9257   17743
Type Resolution                                       175,0367         175,0367   17742
Rulechain Visit                                         1,6539           1,6539   17742
Reporting                                               0,0525           0,0525   17746
File Processing                                       252,8111         252,7726        1
Unaccounted                                             0,8519           0,8519

-------------------------------------------<<< Total  >>>-------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Wall Clock Time                                       253,1100
  • Now:
17700
Resolved: 18006855, unresolved 2591999
Resolved 88.0%
Errors 5
--------------------------------------------<<< Rule >>>--------------------------------------------


Summary:

Label                                              Time (secs) Self Time (secs)  # Calls     Counter

TypeResTest                                             2,4051           2,4051   17742

Total Rule                                              2,4051           2,4051

------------------------------------------<<< Summary  >>>------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Rule                                                    2,4164           0,0113   17742
Rulechain Rule                                          0,0058           0,0058   17742
Collect Files                                           0,3163           0,3163        1
Load Rules                                              0,1324           0,1324        1
Parser                                                 43,7286          43,7286   17743
Qualified Name Resolution                               7,0715           7,0715   17743
Symbol Table                                           27,5194          27,5194   17743
Type Resolution                                        91,8995          91,8995   17742
Rulechain Visit                                         1,7523           1,7523   17742
Reporting                                               0,1810           0,1810   17746
File Processing                                       177,2106         177,0803        1
Unaccounted                                             0,9306           0,9306


-------------------------------------------<<< Total  >>>-------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Wall Clock Time                                       177,7950

Bonus: I tried the same thing with my prototype for 7.0, and got these results:

17700
Resolved: 7276268, unresolved 1161416
Resolved 87.0%
Errors 811
--------------------------------------------<<< Rule >>>--------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

TypeResTest                                            49,6563          49,6563   17742

Total Rule                                             49,6563          49,6563

--------------------------------<<< Language Specific Processing >>>--------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Java: Java processing                                   7,6579           0,0738   17742
Qualified name resolution                               3,5481           3,5481   17742
Symbol table resolution                                 4,0360           4,0360   17742

Total Language Specific Processing                     15,2660           7,6819

------------------------------------------<<< Summary  >>>------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Rule                                                   49,6796           0,0233   17742
Rulechain Rule                                          0,0096           0,0096   17742
Collect Files                                           0,3966           0,3966        1
Load Rules                                              0,1217           0,1217        1
Parser                                                 49,5277          49,5277   17743
Rulechain Ast Indexation                                1,6956           1,6956   17742
Reporting                                               0,0867           0,0867   17746
File Processing                                       111,6540         111,5844        1
Unaccounted                                             1,0617           1,0617

-------------------------------------------<<< Total  >>>-------------------------------------------
Label                                              Time (secs) Self Time (secs)  # Calls     Counter

Wall Clock Time                                       112,2610

So it's nearly 4 times faster than current master. Note that the time is spent in the rule rather than in the processing stage. That's because it's done on demand by the rule. This sample rule resolves all TypeNodes in the tree though. "Qualified name resolution" and "Symbol table resolution" are sub tasks of "Java Processing".

This speeds up type resolution by a factor of 2.
@oowekyala oowekyala added for:performance The goal of this change is to improve PMD's performance in:type-resolution Affects the type resolution code labels Jan 17, 2020
@ghost

ghost commented Jan 17, 2020

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@adangel adangel added this to the 6.22.0 milestone Jan 24, 2020
@adangel adangel merged commit 19d35ff into pmd:master Feb 16, 2020
@oowekyala oowekyala deleted the typeres-no-exceptions branch February 16, 2020 17:33
@oowekyala oowekyala mentioned this pull request Aug 1, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for:performance The goal of this change is to improve PMD's performance in:type-resolution Affects the type resolution code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants