From ac7cb390c9cc9716187847eb78bc5320f966e96d Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Tue, 3 Nov 2026 11:24:41 +0100 Subject: [PATCH] JS: Remove TypeScript parser memory limits Remove extractor-imposed Node heap limits and obsolete TypeScript RAM configuration. Stop interpreting `CODEQL_RAM` in the JavaScript autobuild launchers, but retain `--typescript-ram` as an ignored compatibility option. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7f45b794-38b9-4abc-b652-03279c8dba77 --- .../semmle/js/extractor/ExtractorConfig.java | 14 -------- .../src/com/semmle/js/extractor/Main.java | 15 ++------ .../semmle/ts/extractor/TypeScriptParser.java | 36 ------------------- javascript/resources/tools/autobuild.cmd | 7 ---- javascript/resources/tools/autobuild.sh | 8 ----- 5 files changed, 3 insertions(+), 77 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java b/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java index 538ac1a43679..82c689fb9240 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ExtractorConfig.java @@ -224,9 +224,6 @@ public Set getPredefinedGlobals() { /** Should textual information be extracted into the lines/4 relation? */ private boolean extractLines; - /** Override amount of RAM to allocate to the TypeScript compiler. */ - private int typescriptRam; - /** The default character encoding to use for parsing source files. */ private String defaultEncoding; @@ -267,7 +264,6 @@ public ExtractorConfig(ExtractorConfig that) { this.sourceType = that.sourceType; this.htmlHandling = that.htmlHandling; this.extractLines = that.extractLines; - this.typescriptRam = that.typescriptRam; this.defaultEncoding = that.defaultEncoding; this.virtualSourceRoot = that.virtualSourceRoot; } @@ -426,16 +422,6 @@ public ExtractorConfig withExtractLines(boolean extractLines) { return res; } - public int getTypeScriptRam() { - return typescriptRam; - } - - public ExtractorConfig withTypeScriptRam(int ram) { - ExtractorConfig res = new ExtractorConfig(this); - res.typescriptRam = ram; - return res; - } - public String getDefaultEncoding() { return defaultEncoding; } diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index 03ef253f357e..5ae923d31938 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -20,7 +20,6 @@ import com.semmle.js.parser.ParsedProject; import com.semmle.ts.extractor.TypeScriptParser; import com.semmle.util.data.StringUtil; -import com.semmle.util.data.UnitParser; import com.semmle.util.exception.ResourceError; import com.semmle.util.exception.UserError; import com.semmle.util.extraction.ExtractorOutputConfig; @@ -60,9 +59,9 @@ public class Main { private static final String P_SOURCE_TYPE = "--source-type"; private static final String P_TYPESCRIPT = "--typescript"; private static final String P_TYPESCRIPT_FULL = "--typescript-full"; - private static final String P_TYPESCRIPT_RAM = "--typescript-ram"; // symbolic constants for deprecated command line parameter names + private static final String P_TYPESCRIPT_RAM = "--typescript-ram"; private static final String P_EXCLUDE_PATH = "--exclude-path"; private static final String P_TOLERATE_PARSE_ERRORS = "--tolerate-parse-errors"; private static final String P_NODEJS = "--nodejs"; @@ -130,7 +129,6 @@ public void run(String[] args) { } TypeScriptParser tsParser = extractorState.getTypeScriptParser(); - tsParser.setTypescriptRam(extractorConfig.getTypeScriptRam()); if (containsTypeScriptFiles()) { tsParser.verifyInstallation(!ap.has(P_QUIET)); } @@ -373,10 +371,7 @@ private ArgsParser addArgs(ArgsParser argsParser) { argsParser.addFlag(P_TYPESCRIPT, 0, "Enable basic TypesScript support."); argsParser.addFlag( P_TYPESCRIPT_FULL, 0, "Enable full TypeScript support with static type information."); - argsParser.addFlag( - P_TYPESCRIPT_RAM, - 1, - "Amount of memory allocated to the TypeScript compiler process. The default is 1G."); + argsParser.addToleratedFlag(P_TYPESCRIPT_RAM, 1); argsParser.addToleratedFlag(P_DEBUG_EXCLUSIONS, 0); argsParser.addTrailingParam("files", "Files and directories to extract."); return argsParser; @@ -415,11 +410,7 @@ private ExtractorConfig parseJSOptions(ArgsParser ap) { ap.has(P_EXPERIMENTAL) ? HtmlPopulator.Config.ALL : HtmlPopulator.Config.ELEMENTS)) .withFileType(getFileType(ap)) .withSourceType(ap.getEnum(P_SOURCE_TYPE, SourceType.class, SourceType.AUTO)) - .withExtractLines(ap.has(P_EXTRACT_PROGRAM_TEXT)) - .withTypeScriptRam( - ap.has(P_TYPESCRIPT_RAM) - ? UnitParser.parseOpt(ap.getString(P_TYPESCRIPT_RAM), UnitParser.MEGABYTES) - : 0); + .withExtractLines(ap.has(P_EXTRACT_PROGRAM_TEXT)); if (ap.has(P_DEFAULT_ENCODING)) cfg = cfg.withDefaultEncoding(ap.getString(P_DEFAULT_ENCODING)); // Make a usable virtual source root mapping. diff --git a/javascript/extractor/src/com/semmle/ts/extractor/TypeScriptParser.java b/javascript/extractor/src/com/semmle/ts/extractor/TypeScriptParser.java index 17989d859a9c..20d557380e45 100644 --- a/javascript/extractor/src/com/semmle/ts/extractor/TypeScriptParser.java +++ b/javascript/extractor/src/com/semmle/ts/extractor/TypeScriptParser.java @@ -36,7 +36,6 @@ import com.semmle.js.parser.ParsedProject; import com.semmle.js.parser.JSParser.Result; import com.semmle.util.data.StringUtil; -import com.semmle.util.data.UnitParser; import com.semmle.util.exception.CatastrophicError; import com.semmle.util.exception.Exceptions; import com.semmle.util.exception.InterruptedError; @@ -96,24 +95,6 @@ public class TypeScriptParser { */ public static final String TYPESCRIPT_RETRIES_VAR = "SEMMLE_TYPESCRIPT_RETRIES"; - /** - * An environment variable (without the SEMMLE_ or LGTM_ prefix), that can be - * set to indicate the maximum heap space usable by the Node.js process, in addition to its - * "reserve memory". - * - *

Defaults to 2000 MB (for a total heap space of 2400 MB by default). - */ - public static final String TYPESCRIPT_RAM_SUFFIX = "TYPESCRIPT_RAM"; - - /** - * An environment variable (without the SEMMLE_ or LGTM_ prefix), that can be - * set to indicate the additional heap space added to TYPESCRIPT_RAM when setting the - * Node.js heap limit. - * - *

Defaults to 400 MB (for a total heap space of 2400 MB by default). - */ - public static final String TYPESCRIPT_RAM_RESERVE_SUFFIX = "TYPESCRIPT_RAM_RESERVE"; - /** * An environment variable with additional VM arguments to pass to the Node process. * @@ -154,17 +135,9 @@ public class TypeScriptParser { */ private List nodeJsRuntimeExtraArgs = Collections.emptyList(); - /** If non-zero, we use this instead of relying on the corresponding environment variable. */ - private int typescriptRam = 0; - /** Metadata requested immediately after starting the TypeScript parser. */ private TypeScriptParserMetadata metadata; - /** Sets the amount of RAM to allocate to the TypeScript compiler.s */ - public void setTypescriptRam(int megabytes) { - this.typescriptRam = megabytes; - } - /** * Verifies that Node.js and TypeScript are installed and throws an exception otherwise. * @@ -274,14 +247,6 @@ private List getNodeJsRuntimeInvocation(String... args) { private void setupParserWrapper() { verifyNodeInstallation(); - int mainMemoryMb = - typescriptRam != 0 - ? typescriptRam - : EnvironmentVariables.getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_SUFFIX, 2000); - int reserveMemoryMb = EnvironmentVariables.getMegabyteCountFromPrefixedEnv(TYPESCRIPT_RAM_RESERVE_SUFFIX, 400); - - System.out.println("Memory for TypeScript process: " + mainMemoryMb + " MB, and " + reserveMemoryMb + " MB reserve"); - File parserWrapper = getParserWrapper(); String debugFlagString = Env.systemEnv().getNonEmpty(TYPESCRIPT_NODE_FLAGS); @@ -297,7 +262,6 @@ private void setupParserWrapper() { } List cmd = getNodeJsRuntimeInvocation(); - cmd.add("--max_old_space_size=" + (mainMemoryMb + reserveMemoryMb)); cmd.addAll(debugFlags); cmd.add(parserWrapper.getAbsolutePath()); diff --git a/javascript/resources/tools/autobuild.cmd b/javascript/resources/tools/autobuild.cmd index 72feddeab124..cf97a991ea1a 100644 --- a/javascript/resources/tools/autobuild.cmd +++ b/javascript/resources/tools/autobuild.cmd @@ -3,13 +3,6 @@ SETLOCAL EnableDelayedExpansion set jvm_args=-Xss16m -rem If CODEQL_RAM is set, use half for Java and half for TS. -if NOT [%CODEQL_RAM%] == [] ( - set /a "half_ram=CODEQL_RAM/2" - set LGTM_TYPESCRIPT_RAM=!half_ram! - set jvm_args=!jvm_args! -Xmx!half_ram!m -) - rem If CODEQL_THREADS is set, propagate via LGTM_THREADS. if NOT [%CODEQL_THREADS%] == [] ( set LGTM_THREADS=%CODEQL_THREADS% diff --git a/javascript/resources/tools/autobuild.sh b/javascript/resources/tools/autobuild.sh index 7aaaf2878284..390d1eec30f3 100755 --- a/javascript/resources/tools/autobuild.sh +++ b/javascript/resources/tools/autobuild.sh @@ -4,14 +4,6 @@ set -eu jvm_args=-Xss16m -# If CODEQL_RAM is set, use half for Java and half for TS. -if [ -n "${CODEQL_RAM:-}" ] ; then - half_ram="$(( CODEQL_RAM / 2 ))" - LGTM_TYPESCRIPT_RAM="$half_ram" - export LGTM_TYPESCRIPT_RAM - jvm_args="$jvm_args -Xmx${half_ram}m" -fi - # If CODEQL_THREADS is set, propagate via LGTM_THREADS. if [ -n "${CODEQL_THREADS:-}" ] ; then LGTM_THREADS="$CODEQL_THREADS"