diff --git a/barretenberg/acir_tests/browser-test-app/src/index.ts b/barretenberg/acir_tests/browser-test-app/src/index.ts index c634b2b1a510..56708214eeb6 100644 --- a/barretenberg/acir_tests/browser-test-app/src/index.ts +++ b/barretenberg/acir_tests/browser-test-app/src/index.ts @@ -13,7 +13,7 @@ async function runTest( const CIRCUIT_SIZE = 2 ** 19; debug("starting test..."); - const api = await Barretenberg.new(threads); + const api = await Barretenberg.new({ threads }); // Important to init slab allocator as first thing, to ensure maximum memory efficiency. await api.commonInitSlabAllocator(CIRCUIT_SIZE); diff --git a/barretenberg/ts/README.md b/barretenberg/ts/README.md index 42cd716059af..4e3544af942c 100644 --- a/barretenberg/ts/README.md +++ b/barretenberg/ts/README.md @@ -89,7 +89,7 @@ To create the API and do a blake2s hash: ```typescript import { Crs, Barretenberg, RawBuffer } from './index.js'; -const api = await Barretenberg.new(/* num_threads */ 1); +const api = await Barretenberg.new(/* num_threads */ { threads: 1 }); const input = Buffer.from('hello world!'); const result = await api.blake2s(input); await api.destroy(); diff --git a/barretenberg/ts/src/barretenberg/blake2s.test.ts b/barretenberg/ts/src/barretenberg/blake2s.test.ts index 23c6f9d678f1..49ae654fe74c 100644 --- a/barretenberg/ts/src/barretenberg/blake2s.test.ts +++ b/barretenberg/ts/src/barretenberg/blake2s.test.ts @@ -5,7 +5,7 @@ describe('blake2s async', () => { let api: Barretenberg; beforeAll(async () => { - api = await Barretenberg.new(1); + api = await Barretenberg.new({ threads: 1 }); }); afterAll(async () => { diff --git a/barretenberg/ts/src/barretenberg/common.test.ts b/barretenberg/ts/src/barretenberg/common.test.ts index 5697b2558597..705bcedd8d3c 100644 --- a/barretenberg/ts/src/barretenberg/common.test.ts +++ b/barretenberg/ts/src/barretenberg/common.test.ts @@ -4,7 +4,7 @@ describe('env', () => { let api: Barretenberg; beforeAll(async () => { - api = await Barretenberg.new(3); + api = await Barretenberg.new({ threads: 3 }); }, 15000); afterAll(async () => { diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 6b00a9b752a1..73e935d33728 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -8,6 +8,11 @@ import createDebug from 'debug'; const debug = createDebug('bb.js:wasm'); +export type BackendOptions = { + threads?: number; + memory?: { initial?: number; maximum?: number }; +}; + /** * The main class library consumers interact with. * It extends the generated api, and provides a static constructor "new" to compose components. @@ -23,11 +28,11 @@ export class Barretenberg extends BarretenbergApi { * and blocking the main thread in the browser is not allowed. * It threads > 1 (defaults to hardware availability), child threads will be created on their own workers. */ - static async new(desiredThreads?: number) { + static async new({ threads: desiredThreads, memory }: BackendOptions = {}) { const worker = createMainWorker(); const wasm = getRemoteBarretenbergWasm(worker); const { module, threads } = await fetchModuleAndThreads(desiredThreads); - await wasm.init(module, threads, proxy(debug)); + await wasm.init(module, threads, proxy(debug), memory?.initial, memory?.maximum); return new Barretenberg(worker, wasm); } diff --git a/barretenberg/ts/src/barretenberg/schnorr.test.ts b/barretenberg/ts/src/barretenberg/schnorr.test.ts index 7945cbce3b22..b82195f2a08d 100644 --- a/barretenberg/ts/src/barretenberg/schnorr.test.ts +++ b/barretenberg/ts/src/barretenberg/schnorr.test.ts @@ -8,7 +8,7 @@ describe('schnorr', () => { let api: Barretenberg; beforeAll(async () => { - api = await Barretenberg.new(1); + api = await Barretenberg.new({ threads: 1 }); }, 30000); afterAll(async () => { diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 016c8a63c04c..de4cf64631d6 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -44,7 +44,7 @@ async function computeCircuitSize(bytecodePath: string, api: Barretenberg) { } async function init(bytecodePath: string, crsPath: string) { - const api = await Barretenberg.new(threads); + const api = await Barretenberg.new({ threads }); const circuitSize = await getGates(bytecodePath, api); const subgroupSize = Math.pow(2, Math.ceil(Math.log2(circuitSize))); @@ -70,7 +70,7 @@ async function init(bytecodePath: string, crsPath: string) { } async function initLite() { - const api = await Barretenberg.new(1); + const api = await Barretenberg.new({ threads: 1 }); // Plus 1 needed! (Move +1 into Crs?) const crs = await Crs.new(1); @@ -140,7 +140,7 @@ export async function prove( } export async function gateCount(bytecodePath: string) { - const api = await Barretenberg.new(1); + const api = await Barretenberg.new({ threads: 1 }); try { const numberOfGates = await getGates(bytecodePath, api);