Skip to content

Commit

Permalink
feat: add option to set max memory for bb.js (#4227)
Browse files Browse the repository at this point in the history
# Description

Makes `BackendBarretenberg` pass all the options to the `bb.js`
instance.

## Summary\*

Makes `BackendBarretenberg` pass all the options to the `bb.js`
instance, namely min and max memory. Manually setting max memory makes
iOS not immediately kill workers on the browser.

This is already implemented in BB as per [this
PR](AztecProtocol/aztec-packages#3265)

Replicates the change I made in a pinch for `progrcrypto` Istanbul.
[Example usage
here](https://github.com/signorecello/progcrypto23-act/blob/f95f267f2460a423f99865ca30e29f89e8104bc5/packages/user/pages/index.tsx#L31)
  • Loading branch information
signorecello authored Mar 4, 2024
1 parent aad0da0 commit 8a6b131
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@web/dev-server-esbuild": "^0.3.6",
"@web/dev-server-import-maps": "^0.2.0",
"@web/test-runner": "^0.15.3",
"@web/test-runner-playwright": "^0.10.0",
"eslint": "^8.56.0",
Expand Down
1 change: 1 addition & 0 deletions compiler/integration-tests/test/mocks/os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const os = { cpus: () => new Array(4) };
15 changes: 13 additions & 2 deletions compiler/integration-tests/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { defaultReporter } from '@web/test-runner';
import { summaryReporter } from '@web/test-runner';
import { fileURLToPath } from 'url';
import { esbuildPlugin } from '@web/dev-server-esbuild';
import { playwrightLauncher } from "@web/test-runner-playwright";
import { playwrightLauncher } from '@web/test-runner-playwright';
import { importMapsPlugin } from '@web/dev-server-import-maps';

let reporter = summaryReporter();
const debugPlugins = [];
Expand All @@ -21,14 +22,24 @@ if (process.env.CI !== 'true' || process.env.RUNNER_DEBUG === '1') {

export default {
browsers: [
playwrightLauncher({ product: "chromium" }),
playwrightLauncher({ product: 'chromium' }),
// playwrightLauncher({ product: "webkit" }),
// playwrightLauncher({ product: "firefox" }),
],
plugins: [
esbuildPlugin({
ts: true,
}),
importMapsPlugin({
inject: {
importMap: {
imports: {
// mock os module
os: '/test/mocks/os.js',
},
},
},
}),
...debugPlugins,
],
files: ['test/browser/**/*.test.ts'],
Expand Down
12 changes: 11 additions & 1 deletion tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ export class BarretenbergBackend implements Backend {
/** @ignore */
async instantiate(): Promise<void> {
if (!this.api) {
if (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) {
this.options.threads = navigator.hardwareConcurrency;
} else {
try {
const os = await import('os');
this.options.threads = os.cpus().length;
} catch (e) {
console.log('Could not detect environment. Falling back to one thread.', e);
}
}
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);
Expand Down
1 change: 1 addition & 0 deletions tooling/noir_js_backend_barretenberg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
export type BackendOptions = {
/** @description Number of threads */
threads: number;
memory?: { maximum: number };
};
22 changes: 22 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3951,6 +3951,13 @@ __metadata:
languageName: node
linkType: hard

"@import-maps/resolve@npm:^1.0.1":
version: 1.0.1
resolution: "@import-maps/resolve@npm:1.0.1"
checksum: 17ee033e26a0fd82294de87eae76d32b553a130fdbf0fb8c70d39f2087a3e8a4a5908970a99aa32bd175153efe9b7dfee6b7f99df36f41abed08c1911dbdb19c
languageName: node
linkType: hard

"@isaacs/cliui@npm:^8.0.2":
version: 8.0.2
resolution: "@isaacs/cliui@npm:8.0.2"
Expand Down Expand Up @@ -6677,6 +6684,20 @@ __metadata:
languageName: node
linkType: hard

"@web/dev-server-import-maps@npm:^0.2.0":
version: 0.2.0
resolution: "@web/dev-server-import-maps@npm:0.2.0"
dependencies:
"@import-maps/resolve": ^1.0.1
"@types/parse5": ^6.0.1
"@web/dev-server-core": ^0.7.0
"@web/parse5-utils": ^2.1.0
parse5: ^6.0.1
picomatch: ^2.2.2
checksum: 15dabfa385f023bab70758b80cc09443455830799793c1a404a7230d90ebf60e40984a10d8a6ceea2afb8f057e90a9f7356a76f867d5e5a2eeacbc397e41535a
languageName: node
linkType: hard

"@web/dev-server-rollup@npm:^0.4.1":
version: 0.4.1
resolution: "@web/dev-server-rollup@npm:0.4.1"
Expand Down Expand Up @@ -13416,6 +13437,7 @@ __metadata:
"@nomicfoundation/hardhat-chai-matchers": ^2.0.0
"@nomicfoundation/hardhat-ethers": ^3.0.0
"@web/dev-server-esbuild": ^0.3.6
"@web/dev-server-import-maps": ^0.2.0
"@web/test-runner": ^0.15.3
"@web/test-runner-playwright": ^0.10.0
eslint: ^8.56.0
Expand Down

0 comments on commit 8a6b131

Please sign in to comment.