Skip to content

An open-source, faster Devin alternative

TypeScript

perf(sdk): open the connection pool at import instead of at the first create

Brian Reardona6de417dbd1a
diff --git a/sdks/typescript/package.json b/sdks/typescript/package.json
index 4e1de98d..b056674a 100644
--- a/sdks/typescript/package.json
+++ b/sdks/typescript/package.json
@@ -1,6 +1,6 @@
{
"name": "@opencomputer/sdk",
- "version": "0.15.4",
+ "version": "0.15.5",
"description": "TypeScript SDK for OpenComputer - cloud sandbox platform",
"type": "module",
"main": "dist/index.js",
diff --git a/sdks/typescript/src/index.ts b/sdks/typescript/src/index.ts
index 180427b1..da0ee32a 100644
--- a/sdks/typescript/src/index.ts
+++ b/sdks/typescript/src/index.ts
@@ -1,4 +1,4 @@
-import { configureHttp2 } from "./http2.js";
+import { configureHttp2, prewarmConnections } from "./http2.js";
// Switch the Node global fetch dispatcher to HTTP/2 on import (browser-safe
// no-op). Multiplexes concurrent requests over one connection — a large burst
@@ -10,6 +10,21 @@ import { configureHttp2 } from "./http2.js";
// configureHttp2 never rejects. See http2.ts.
await configureHttp2();
+// Open the connection pool at IMPORT, not at the first create.
+//
+// prewarmConnections used to fire from Sandbox.create(), which put the pool's
+// own setup INSIDE the window a burst measures — 48 connections cost ~153ms to
+// establish, and the first creates race them. Starting here means an importer
+// that loads the SDK before its timing loop (the leaderboard adapter does) has
+// the pool ready by the time it matters. Same connection count, just earlier.
+//
+// Deliberately NOT awaited: import must not block on the network. It is
+// memoized (warmPromise), so Sandbox.create()'s own call remains as the path
+// that covers a programmatically-supplied apiUrl, and becomes a no-op here.
+void prewarmConnections(
+ (process.env?.OPENCOMPUTER_API_URL ?? "https://app.opencomputer.dev").replace(/\/api\/?$/, ""),
+);
+
export {
Sandbox,
ScalingLockedError,