diff --git a/barretenberg/ts/src/barretenberg/index.ts b/barretenberg/ts/src/barretenberg/index.ts index 73e935d33728..028bd7a87f1a 100644 --- a/barretenberg/ts/src/barretenberg/index.ts +++ b/barretenberg/ts/src/barretenberg/index.ts @@ -10,7 +10,7 @@ const debug = createDebug('bb.js:wasm'); export type BackendOptions = { threads?: number; - memory?: { initial?: number; maximum?: number }; + memory?: { maximum: number }; }; /** @@ -32,7 +32,7 @@ export class Barretenberg extends BarretenbergApi { const worker = createMainWorker(); const wasm = getRemoteBarretenbergWasm(worker); const { module, threads } = await fetchModuleAndThreads(desiredThreads); - await wasm.init(module, threads, proxy(debug), memory?.initial, memory?.maximum); + await wasm.init(module, threads, proxy(debug), memory?.maximum); return new Barretenberg(worker, wasm); } diff --git a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts index f8c07e323b0e..bd64c6310f6a 100644 --- a/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +++ b/barretenberg/ts/src/barretenberg_wasm/barretenberg_wasm_main/index.ts @@ -32,8 +32,8 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase { module: WebAssembly.Module, threads = Math.min(getNumCpu(), BarretenbergWasmMain.MAX_THREADS), logger: (msg: string) => void = debug, - initial = 26, maximum = 2 ** 16, + initial = 26, ) { this.logger = logger; diff --git a/noir/tooling/noir_js_backend_barretenberg/src/index.ts b/noir/tooling/noir_js_backend_barretenberg/src/index.ts index d79b487c3cf6..cbbd15e38b5a 100644 --- a/noir/tooling/noir_js_backend_barretenberg/src/index.ts +++ b/noir/tooling/noir_js_backend_barretenberg/src/index.ts @@ -4,6 +4,7 @@ import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types'; import { BackendOptions } from './types.js'; import { deflattenPublicInputs, flattenPublicInputsAsArray } from './public_inputs.js'; import { type Barretenberg } from '@aztec/bb.js'; +import { cpus } from 'os'; export { publicInputsToWitnessMap } from './public_inputs.js'; @@ -24,7 +25,7 @@ export class BarretenbergBackend implements Backend { constructor( acirCircuit: CompiledCircuit, - private options: BackendOptions = { threads: 1 }, + private options: BackendOptions = { threads: navigator ? navigator.hardwareConcurrency : cpus().length }, ) { const acirBytecodeBase64 = acirCircuit.bytecode; this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64); @@ -34,7 +35,7 @@ export class BarretenbergBackend implements Backend { async instantiate(): Promise { if (!this.api) { const { Barretenberg, RawBuffer, Crs } = await import('@aztec/bb.js'); - const api = await Barretenberg.new({ threads: this.options.threads }); + const api = await Barretenberg.new(this.options); const [_exact, _total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode); const crs = await Crs.new(subgroupSize + 1); diff --git a/noir/tooling/noir_js_backend_barretenberg/src/types.ts b/noir/tooling/noir_js_backend_barretenberg/src/types.ts index 041e36fdf91c..ab5a89541de8 100644 --- a/noir/tooling/noir_js_backend_barretenberg/src/types.ts +++ b/noir/tooling/noir_js_backend_barretenberg/src/types.ts @@ -5,4 +5,6 @@ export type BackendOptions = { /** @description Number of threads */ threads: number; + /** @description Maximum memory to be allocated to the WASM (optional) */ + memory?: { maximum: number }; };