perf: skip tsgo declaration transforms

This commit is contained in:
Peter Steinberger
2026-04-10 15:51:38 +01:00
parent 56fc20fb7c
commit e9fb4c7f93
2 changed files with 30 additions and 4 deletions

View File

@@ -27,6 +27,10 @@ export function applyLocalTsgoPolicy(args, env, hostResources) {
const nextEnv = { ...env };
const nextArgs = [...args];
if (!hasFlag(nextArgs, "--declaration") && !nextArgs.includes("-d")) {
insertBeforeSeparator(nextArgs, "--declaration", "false");
}
if (!isLocalCheckEnabled(nextEnv)) {
return { env: nextEnv, args: nextArgs };
}

View File

@@ -31,11 +31,17 @@ describe("local-heavy-check-runtime", () => {
it("tightens local tsgo runs on constrained hosts", () => {
const { args, env } = applyLocalTsgoPolicy([], makeEnv(), CONSTRAINED_HOST);
expect(args).toEqual(["--singleThreaded", "--checkers", "1"]);
expect(args).toEqual(["--declaration", "false", "--singleThreaded", "--checkers", "1"]);
expect(env.GOGC).toBe("30");
expect(env.GOMEMLIMIT).toBe("3GiB");
});
it("skips declaration transforms for no-emit tsgo checks", () => {
const { args } = applyLocalTsgoPolicy([], makeEnv({ OPENCLAW_LOCAL_CHECK: "0" }), ROOMY_HOST);
expect(args).toEqual(["--declaration", "false"]);
});
it("keeps explicit tsgo flags and Go env overrides intact when throttled", () => {
const { args, env } = applyLocalTsgoPolicy(
["--checkers", "4", "--singleThreaded", "--pprofDir", "/tmp/existing"],
@@ -47,15 +53,31 @@ describe("local-heavy-check-runtime", () => {
CONSTRAINED_HOST,
);
expect(args).toEqual(["--checkers", "4", "--singleThreaded", "--pprofDir", "/tmp/existing"]);
expect(args).toEqual([
"--checkers",
"4",
"--singleThreaded",
"--pprofDir",
"/tmp/existing",
"--declaration",
"false",
]);
expect(env.GOGC).toBe("80");
expect(env.GOMEMLIMIT).toBe("5GiB");
});
it("keeps explicit tsgo declaration flags intact", () => {
const longFlag = applyLocalTsgoPolicy(["--declaration"], makeEnv(), ROOMY_HOST);
const shortFlag = applyLocalTsgoPolicy(["-d"], makeEnv(), ROOMY_HOST);
expect(longFlag.args).toEqual(["--declaration"]);
expect(shortFlag.args).toEqual(["-d"]);
});
it("keeps local tsgo at full speed on roomy hosts in auto mode", () => {
const { args, env } = applyLocalTsgoPolicy([], makeEnv(), ROOMY_HOST);
expect(args).toEqual([]);
expect(args).toEqual(["--declaration", "false"]);
expect(env.GOGC).toBeUndefined();
expect(env.GOMEMLIMIT).toBeUndefined();
});
@@ -69,7 +91,7 @@ describe("local-heavy-check-runtime", () => {
ROOMY_HOST,
);
expect(args).toEqual(["--singleThreaded", "--checkers", "1"]);
expect(args).toEqual(["--declaration", "false", "--singleThreaded", "--checkers", "1"]);
expect(env.GOGC).toBe("30");
expect(env.GOMEMLIMIT).toBe("3GiB");
});