Skip to content

Commit 6013b91

Browse files
author
Max Schaefer
committed
JavaScript: Extract tokens and comments before AST.
This allows us to discard token/comment information sooner, thereby reducing heap pressure for very large files.
1 parent aa54d67 commit 6013b91

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

javascript/extractor/src/com/semmle/js/extractor/JSExtractor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ public Pair<Label, LoCInfo> extract(TextualExtractor textualExtractor,
9494
ASTExtractor scriptExtractor = new ASTExtractor(lexicalExtractor, scopeManager);
9595
toplevelLabel = scriptExtractor.getToplevelLabel();
9696

97-
scriptExtractor.extract(ast, platform, sourceType, toplevelKind);
9897
lexicalExtractor.extractComments(toplevelLabel);
9998
loc = lexicalExtractor.extractLines(parserRes.getSource(), toplevelLabel);
10099
lexicalExtractor.extractTokens(toplevelLabel);
101-
new CFGExtractor(scriptExtractor).extract(ast);
102100
new JSDocExtractor(textualExtractor).extract(lexicalExtractor.getComments());
101+
lexicalExtractor.purge();
102+
103+
scriptExtractor.extract(ast, platform, sourceType, toplevelKind);
104+
new CFGExtractor(scriptExtractor).extract(ast);
103105
} else {
104106
lexicalExtractor = new LexicalExtractor(textualExtractor, new ArrayList<Token>(), new ArrayList<Comment>());
105107
ASTExtractor scriptExtractor = new ASTExtractor(lexicalExtractor, null);

javascript/extractor/src/com/semmle/js/extractor/LexicalExtractor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,12 @@ public void extractComments(Label toplevelKey) {
173173
public String mkToString(SourceElement nd) {
174174
return textualExtractor.mkToString(nd);
175175
}
176+
177+
/**
178+
* Purge token and comments information to reduce heap pressure.
179+
*/
180+
public void purge() {
181+
this.tokens.clear();
182+
this.comments.clear();
183+
}
176184
}

0 commit comments

Comments
 (0)