Skip to content

Commit c244394

Browse files
committed
fix(engine): importing the engine no longer runs a subprocess for audio effects
The audio effects Chrome flags were built when the module loaded, which ran the GPU memory lookup (nvidia-smi) on every import of the engine. They are now built on the first audio effects launch and reused. A test imports the engine with child_process mocked and expects no call.
1 parent 783f37e commit c244394

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
3+
const execSync = vi.hoisted(() => vi.fn(() => ""));
4+
vi.mock("child_process", async (importActual) => ({
5+
...(await importActual<typeof import("child_process")>()),
6+
execSync,
7+
}));
8+
9+
describe("importing the engine", () => {
10+
it("runs no subprocess", async () => {
11+
await import("./audioFxRender.js");
12+
await import("../index.js");
13+
expect(execSync).not.toHaveBeenCalled();
14+
}, 60_000);
15+
});

‎packages/engine/src/services/audioFxRender.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,12 @@ export async function applyAudioFxChain(
607607
}
608608

609609
/** Audio processing needs no GPU, so software mode; every other launch detail is the shared one. */
610-
const FX_BROWSER_ARGS = buildChromeArgs(
611-
{ width: 1280, height: 720, captureMode: "screenshot" },
612-
{ browserGpuMode: "software" },
613-
);
610+
let fxBrowserArgs: string[] | undefined;
611+
const fxChromeArgs = () =>
612+
(fxBrowserArgs ??= buildChromeArgs(
613+
{ width: 1280, height: 720, captureMode: "screenshot" },
614+
{ browserGpuMode: "software" },
615+
));
614616

615617
/** Run `body` with a leased browser and a way to open pages on the runtime; both are released in the same try that takes them. */
616618
async function withFxBrowser<T>(
@@ -627,7 +629,7 @@ async function withFxBrowser<T>(
627629
if (options.signal?.aborted) {
628630
throw new AudioFxRenderError(`Audio FX cancelled for track ${options.trackId}`);
629631
}
630-
lease = await acquireBrowser(FX_BROWSER_ARGS);
632+
lease = await acquireBrowser(fxChromeArgs());
631633
const { browser } = lease;
632634
return await body(() => openFxPage(browser, hostDir));
633635
} catch (err) {

0 commit comments

Comments
 (0)