From ef4435fb856e90298cdbb9558eabbe92df315b21 Mon Sep 17 00:00:00 2001 From: jackryanservia <90076280+jackryanservia@users.noreply.github.com> Date: Wed, 21 Feb 2024 20:59:46 -0700 Subject: [PATCH 1/6] Update to spawn workers for all logical cores and expose global function to allow user override --- src/bindings | 2 +- src/index.ts | 2 ++ src/lib/proof-system/workers.ts | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/lib/proof-system/workers.ts diff --git a/src/bindings b/src/bindings index a7ade0db48..7b36887243 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit a7ade0db4879afeb603c246c967098e0ca6170b5 +Subproject commit 7b368872437b7313cc627c32a76aaef586c2f93b diff --git a/src/index.ts b/src/index.ts index 865bb01d05..6445ab3706 100644 --- a/src/index.ts +++ b/src/index.ts @@ -117,6 +117,8 @@ export { Crypto } from './lib/crypto.js'; export type { NetworkId } from './mina-signer/mina-signer.js'; +export { setNumberOfWorkers } from './lib/proof-system/workers.js'; + // experimental APIs import { memoizeWitness } from './lib/provable.js'; export { Experimental }; diff --git a/src/lib/proof-system/workers.ts b/src/lib/proof-system/workers.ts new file mode 100644 index 0000000000..52db5fc0e6 --- /dev/null +++ b/src/lib/proof-system/workers.ts @@ -0,0 +1,15 @@ +export const workers = { + numWorkers: undefined as number | undefined, +}; + +/** + * Set the number of workers to use for parallelizing the proof generation. By default the number of workers is set to the number of physical CPU cores on your machine, but there may be some instances where you want to set the number of workers manually. Some machines may have a large number of cores, but not enough memory to support that many workers. In that case, you can set the number of workers to a lower number to avoid running out of memory. On the other hand, some machines with heterogeneous cores may benefit from setting the number of workers to a lower number to avoid contention between core types if load-link/store-conditional multithreading is used. Feel free to experiment and see what works best for your use case. Maybe you can squeeze slightly more performance out by tweaking this value :) + + * @example + * ```typescript + * setNumberOfWorkers(2); // set the number of workers to 2 + * ``` + */ +export const setNumberOfWorkers = (numWorkers: number) => { + workers.numWorkers = numWorkers; +}; From a93b1fa1085766d26e7c0f296c676f7f9a925e8a Mon Sep 17 00:00:00 2001 From: jackryanservia <90076280+jackryanservia@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:00:32 -0700 Subject: [PATCH 2/6] Remove dependency: detect-gpu --- package-lock.json | 14 -------------- package.json | 1 - 2 files changed, 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5cba08e5e2..5059ee4c27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "blakejs": "1.2.1", "cachedir": "^2.4.0", - "detect-gpu": "^5.0.5", "isomorphic-fetch": "^3.0.0", "js-sha256": "^0.9.0", "reflect-metadata": "^0.1.13", @@ -2641,14 +2640,6 @@ "node": ">=0.10.0" } }, - "node_modules/detect-gpu": { - "version": "5.0.37", - "resolved": "https://registry.npmjs.org/detect-gpu/-/detect-gpu-5.0.37.tgz", - "integrity": "sha512-EraWs84faI4iskB4qvE39bevMIazEvd1RpoyGLOBesRLbiz6eMeJqqRPHjEFClfRByYZzi9IzU35rBXIO76oDw==", - "dependencies": { - "webgl-constants": "^1.1.1" - } - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -6652,11 +6643,6 @@ "makeerror": "1.0.12" } }, - "node_modules/webgl-constants": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/webgl-constants/-/webgl-constants-1.1.1.tgz", - "integrity": "sha512-LkBXKjU5r9vAW7Gcu3T5u+5cvSvh5WwINdr0C+9jpzVB41cjQAP5ePArDtk/WHYdVj0GefCgM73BA7FlIiNtdg==" - }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", diff --git a/package.json b/package.json index fb3856ef3a..90af8aa90f 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,6 @@ "dependencies": { "blakejs": "1.2.1", "cachedir": "^2.4.0", - "detect-gpu": "^5.0.5", "isomorphic-fetch": "^3.0.0", "js-sha256": "^0.9.0", "reflect-metadata": "^0.1.13", From d5be6578f59640cdec80c83913045a2377e646ea Mon Sep 17 00:00:00 2001 From: jackryanservia <90076280+jackryanservia@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:40:12 -0700 Subject: [PATCH 3/6] Added CHANGELOG entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8669e21a4b..4e503f78bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Support for custom network identifiers other than `mainnet` or `testnet` https://github.com/o1-labs/o1js/pull/1444 - `PrivateKey.randomKeypair()` to generate private and public key in one command https://github.com/o1-labs/o1js/pull/1446 +- `setNumberOfWorkers()` to allow developer to override the number of workers used during compilation and proof generation/verification https://github.com/o1-labs/o1js/pull/1456 + +### Changed + +- Improve all-around performance by reverting the Apple silicon workaround (https://github.com/o1-labs/o1js/pull/683) as the root problem is now fixed upstream https://github.com/o1-labs/o1js/pull/1456 ### Deprecated From 1b12eba6f6968d58e14408f62720cfdd44973e82 Mon Sep 17 00:00:00 2001 From: jackryanservia <90076280+jackryanservia@users.noreply.github.com> Date: Thu, 22 Feb 2024 01:32:32 -0700 Subject: [PATCH 4/6] Bump bindings --- src/bindings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings b/src/bindings index 7b36887243..2baae6c47d 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 7b368872437b7313cc627c32a76aaef586c2f93b +Subproject commit 2baae6c47d76964d2ca1eeb5684152aeaec91ae4 From 46fa17c9836f760ebee1c66ae429a1551325a13d Mon Sep 17 00:00:00 2001 From: jackryanservia <90076280+jackryanservia@users.noreply.github.com> Date: Thu, 22 Feb 2024 01:34:49 -0700 Subject: [PATCH 5/6] Declare export at top of file :) --- src/lib/proof-system/workers.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/proof-system/workers.ts b/src/lib/proof-system/workers.ts index 52db5fc0e6..9076ad7554 100644 --- a/src/lib/proof-system/workers.ts +++ b/src/lib/proof-system/workers.ts @@ -1,4 +1,6 @@ -export const workers = { +export { workers, setNumberOfWorkers }; + +const workers = { numWorkers: undefined as number | undefined, }; @@ -10,6 +12,6 @@ export const workers = { * setNumberOfWorkers(2); // set the number of workers to 2 * ``` */ -export const setNumberOfWorkers = (numWorkers: number) => { +const setNumberOfWorkers = (numWorkers: number) => { workers.numWorkers = numWorkers; }; From 9236c384ebd47bc1fb4a774746e22394290f2e71 Mon Sep 17 00:00:00 2001 From: jackryanservia <90076280+jackryanservia@users.noreply.github.com> Date: Thu, 22 Feb 2024 15:17:48 -0700 Subject: [PATCH 6/6] Bump bindings --- src/bindings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings b/src/bindings index 2baae6c47d..b33a7eab09 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 2baae6c47d76964d2ca1eeb5684152aeaec91ae4 +Subproject commit b33a7eab09f6fda33b982a6cde67a51507b6b72e