Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to set max memory for bb.js #4227

Merged
merged 5 commits into from
Mar 4, 2024
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
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.50.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 };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a /** @description ... */ to supplement the BackendOptions doc page?

Describing e.g. this being the maximum memory limit, unit of the number (MB? GB?), etc.

};
22 changes: 22 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3965,6 +3965,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 @@ -6759,6 +6766,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 @@ -13400,6 +13421,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.50.0
Expand Down
Loading