Skip to content

Commit

Permalink
Remove unnecessary runs of PureFunctionIdentifier in J2ClClinitPruner…
Browse files Browse the repository at this point in the history
…Pass.

Only one of the optimizations may change the side-effect of the functions which is EmptyClinitPruner. Others only removes the redundant ones so should not have any impact on side-effect state.

PureFunctionIdentier is taking 4.0% percent of total run-time, so I'm guessing this should significantly help with that.

No code size changes in j2cl tests.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=164914270
  • Loading branch information
gkdn authored and blickly committed Aug 11, 2017
1 parent 512ef59 commit 5b6b18b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/com/google/javascript/jscomp/J2clClinitPrunerPass.java
Expand Up @@ -35,7 +35,7 @@
public class J2clClinitPrunerPass implements CompilerPass {

private final AbstractCompiler compiler;
private boolean madeChange = false;
private boolean newEmptyClinitMethod = false;
private final List<Node> changedScopeNodes;

J2clClinitPrunerPass(AbstractCompiler compiler, List<Node> changedScopeNodes) {
Expand All @@ -62,8 +62,7 @@ public void process(Node externs, Node root) {
NodeTraversal.traverseEs6ScopeRoots(
compiler, root, changedScopeNodes, new EmptyClinitPruner(), false);

if (madeChange) {
// This invocation is ~70% of ALL the cost of j2clOptBundlePass :(
if (newEmptyClinitMethod) {
new PureFunctionIdentifier.Driver(compiler, null).process(externs, root);
}
}
Expand Down Expand Up @@ -137,7 +136,6 @@ private void tryRemovingClinit(Node node, Node parent) {
// Replacing with undefined is a simple way of removing without introducing invalid AST.
parent.replaceChild(node, NodeUtil.newUndefinedNode(node));
compiler.reportChangeToEnclosingScope(parent);
madeChange = true;
}

private boolean isNewControlBranch(Node n) {
Expand Down Expand Up @@ -190,12 +188,11 @@ public void visit(NodeTraversal t, Node node, Node parent) {
return;
}

// Check that the clinit is safe to prune.
// Check that the clinit call is safe to prune.
Node staticFnNode = var.getInitialValue();
if (callsClinit(staticFnNode, clinitName) && hasSafeArguments(t, callOrNewNode)) {
parent.removeChild(node);
compiler.reportChangeToEnclosingScope(parent);
madeChange = true;
}
}

Expand Down Expand Up @@ -302,7 +299,7 @@ private void trySubstituteEmptyFunction(Node fnNode) {
body.removeChild(firstExpr);
NodeUtil.markFunctionsDeleted(firstExpr, compiler);
compiler.reportChangeToEnclosingScope(body);
madeChange = true;
newEmptyClinitMethod = true;
}

private boolean isAssignToEmptyFn(Node node, String enclosingFnName) {
Expand Down

0 comments on commit 5b6b18b

Please sign in to comment.