The RuleChain improves performance of rule application by allowing several
rules to run on a single trasversal of the AST.
Unless your rule depends on the order in which the nodes are visited
(shouldn't!) it will make no difference for the rule, but will improve
runtime performance.
another question is why the src code gets RuleSets twice? why not use the
first RuleSets? thank you very much
I have no idea at what point of the source code you are referring to.
Oh, that's because RuleSet / Rules are not required to be thread-safe, and
PMD can work on multiple threads. So PMD provides each thread with it's own
set of rule instances it can work with without locking / worrying.
// render base report first - general errors
renderReports(renderers, ctx.getReport());
// then add analysis results per file
collectReports(renderers);
}
~~~
why not just use the first ruleset all the time?
public void processFiles(RuleSetFactory ruleSetFactory, List<DataSource> files, RuleContext ctx,
List<Renderer> renderers) {
**RuleSets rs = createRuleSets(ruleSetFactory, ctx.getReport());**
configuration.getAnalysisCache().checkValidity(rs, configuration.getClassLoader());
SourceCodeProcessor processor = new SourceCodeProcessor(configuration);
for (DataSource dataSource : files) {
String niceFileName = filenameFrom(dataSource);
**runAnalysis(new PmdRunnable(dataSource, niceFileName, renderers, ctx, rs, processor));**
}
// render base report first - general errors
renderReports(renderers, ctx.getReport());
// then add analysis results per file
collectReports(renderers);
}
I think this line "RuleSets rs = createRuleSets(ruleSetFactory, ctx.getReport());" doesn't create thread-local rulesets, instead, it creates new rulesets from the ruleset .xml files(which is identical to the first rulesets), but this line "runAnalysis(new PmdRunnable(dataSource, niceFileName, renderers, ctx, rs, processor))" creates thread-local rulesets from rs. if we don't create rs from .xml file, instead we use the first ruleset to create the thread-local ruleset, we will save some time. is this right?
Last edit: supermanheng21 2018-09-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
// render base report first - general errors
renderReports(renderers, ctx.getReport());
// then add analysis results per file
collectReports(renderers);
}
~~~
I think this line "RuleSets rs = createRuleSets(ruleSetFactory,
ctx.getReport());" doesn't create thread-local rulesets, it creates new
rulesets from the ruleset .xml files(which is identical to the first
rulesets), but this line "runAnalysis(new PmdRunnable(dataSource,
niceFileName, renderers, ctx, rs, processor))" create thread-local rulesets
from rs. if we don't create rs from .xml file, instead we use the first
ruleset to create the thread-local ruleset, we will save some time. is
this right?
There is little documentation for these. Other than typeResolution, which
is the maximum mature and all document is focused on consuming kind facts to install apk.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
what is the difference between rulechian.apply() and ruleSet.apply(), why to use rulechain here?
Last edit: supermanheng21 2018-09-03
another question is why the src code gets RuleSets twice? why not use the first RuleSets? thank you very much
The RuleChain improves performance of rule application by allowing several
rules to run on a single trasversal of the AST.
Unless your rule depends on the order in which the nodes are visited
(shouldn't!) it will make no difference for the rule, but will improve
runtime performance.
I have no idea at what point of the source code you are referring to.
On Mon, Sep 3, 2018 at 6:32 AM supermanheng21 supermanheng21@users.sourceforge.net wrote:
the first rulesets is created in pmd-core/net/sourceforge/pmd/PMD.doPMD():
the second rulesets is created in pmd-core/net/sourceforge/pmd/processor/AbstractPMDProcessor.java
why not just use the first ruleset all the time?
Oh, that's because RuleSet / Rules are not required to be thread-safe, and
PMD can work on multiple threads. So PMD provides each thread with it's own
set of rule instances it can work with without locking / worrying.
On Tue, Sep 4, 2018 at 10:38 AM supermanheng21 supermanheng21@users.sourceforge.net wrote:
I think this line "RuleSets rs = createRuleSets(ruleSetFactory, ctx.getReport());" doesn't create thread-local rulesets, instead, it creates new rulesets from the ruleset .xml files(which is identical to the first rulesets), but this line "runAnalysis(new PmdRunnable(dataSource, niceFileName, renderers, ctx, rs, processor))" creates thread-local rulesets from rs. if we don't create rs from .xml file, instead we use the first ruleset to create the thread-local ruleset, we will save some time. is this right?
Last edit: supermanheng21 2018-09-05
You may be on to something... it's quite some time since I last checked
that code but it's plausible.
I'm currently reworking ruleset parsing as part of
https://github.com/pmd/pmd/issues/724. I'll make sure to look into this as
part of that.
Thanks for your insight.
On Tue, Sep 4, 2018 at 11:14 PM supermanheng21 supermanheng21@users.sourceforge.net wrote:
thank you for your reply.
thank you for your reply.
There is little documentation for these. Other than typeResolution, which
is the maximum mature and all document is focused on consuming kind facts to install apk.