Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
blaine-arcjet committed Jan 14, 2025
1 parent 124e5aa commit 55b3608
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 38 deletions.
19 changes: 3 additions & 16 deletions analyze-wasm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,19 @@ import { wasm as componentCore3Wasm } from "./wasm/arcjet_analyze_js_req.compone
type DetectSensitiveInfoFunction =
typeof ArcjetJsReqSensitiveInformationIdentifier.detect;

const wasmCache = new Map<string, WebAssembly.Module>();

const componentCoreWasmPromise = componentCoreWasm();
const componentCore2WasmPromise = componentCore2Wasm();
const componentCore3WasmPromise = componentCore3Wasm();

async function moduleFromPath(path: string): Promise<WebAssembly.Module> {
const cachedModule = wasmCache.get(path);
if (typeof cachedModule !== "undefined") {
return cachedModule;
}

if (path === "arcjet_analyze_js_req.component.core.wasm") {
const mod = await componentCoreWasmPromise;
wasmCache.set(path, mod);
return mod;
return componentCoreWasmPromise;
}
if (path === "arcjet_analyze_js_req.component.core2.wasm") {
const mod = await componentCore2WasmPromise;
wasmCache.set(path, mod);
return mod;
return componentCore2WasmPromise;
}
if (path === "arcjet_analyze_js_req.component.core3.wasm") {
const mod = await componentCore3WasmPromise;
wasmCache.set(path, mod);
return mod;
return componentCore3WasmPromise;
}

throw new Error(`Unknown path: ${path}`);
Expand Down
11 changes: 0 additions & 11 deletions analyze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,6 @@ function createCoreImports(detect?: DetectSensitiveInfoFunction): ImportObject {
};
}

/**
* Pre-warms the wasm cache to improve cold start performance.
* @returns Whether the cache was successfully warmed or not.
*/
export async function prewarmWasmCache(): Promise<boolean> {
const coreImports = createCoreImports();
const analyze = await initializeWasm(coreImports);

return typeof analyze !== "undefined";
}

/**
* Generate a fingerprint for the client. This is used to identify the client
* across multiple requests.
Expand Down
11 changes: 0 additions & 11 deletions arcjet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,6 @@ export default function arcjet<
}
const log = options.log;

const wasmPrewarm = analyze.prewarmWasmCache();

const perf = new Performance(log);

// TODO(#207): Remove this when we can default the transport so client is not required
Expand Down Expand Up @@ -1300,15 +1298,6 @@ export default function arcjet<
...ctx,
};

const logWasmPrewarmPerf = perf.measure("wasm prewarm");
const prewarmed = await wasmPrewarm;
if (!prewarmed) {
log.debug(
"Wasm prewarm failed. This may indicate that Wasm is not supported on this platform",
);
}
logWasmPrewarmPerf();

let fingerprint = "";

const logFingerprintPerf = perf.measure("fingerprint");
Expand Down

0 comments on commit 55b3608

Please sign in to comment.