Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/browser-test-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/src/barretenberg/blake2s.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/src/barretenberg/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
9 changes: 7 additions & 2 deletions barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<BarretenbergWasmMainWorker>(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);
}

Expand Down
2 changes: 1 addition & 1 deletion barretenberg/ts/src/barretenberg/schnorr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions barretenberg/ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down