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

Move gates parsing from proving #12

Open
AllFi opened this issue Mar 28, 2023 · 4 comments
Open

Move gates parsing from proving #12

AllFi opened this issue Mar 28, 2023 · 4 comments
Assignees
Labels

Comments

@AllFi
Copy link

AllFi commented Mar 28, 2023

I have profiled our proving process and discovered that a significant portion of the process involves decompressing and parsing gates.
image

We can decompress and parse the gates during the parameters initialization phase, which means we can move this process from the proving phase to the initialization phase. Since parameter initialization now takes place in the background, preprocessing will mostly be finished before the first proving in most cases.

I've tried to implement it, and here are some results of the decreased proving time:

  • Laptop (WASM) (Intel(R) Core(TM) i7-10750H): -18 %
  • Laptop (Native) (Intel(R) Core(TM) i7-10750H): -35 %
  • Laptop (WASM) (Intel Core i7 (2.9 GHz, 4 cores\8 threads)): -14 %
  • MAC M1 (WASM): -16 %
  • Android (WASM) (Galaxy S23): -18 %
  • iOS (WASM) (iPhone 11): -18 %

But the size of the decompressed gates is huge, it's about 260 MB. Here are some potential drawbacks of this modification:

  • Parameter initialization time is likely to increase due to the need to decompress and parse the gates. However, it is important to note that this is a one-time cost during the initialization phase and it can result in significant time savings during the proving phase.
  • The RAM usage of the application will increase from 420 MB to 680 MB.
  • WebAssembly.Memory.grow(..) is extremely slow on iOS, so we need to compute the necessary memory size and allocate it with a single call. This results in some time overhead during the parameter initialization phase.
  • Mobile versions of Chrome and Safari have a strict limit on memory usage (500-800 mb, it depends on fragmentation), and attempting to exceed that limit can cause the application to crash. So this optimization is generally not feasible for mobile devices.

I think that this optimization makes sense for delegated prover and cloud environments, and may also make sense for PC. However, it is definitely not viable for mobile devices due to their limited memory capacity.

Related PRs:

Note: It is necessary to update zkbob-cloud and zkbob-prover to include the changes introduced in this PR.

@AllFi
Copy link
Author

AllFi commented Apr 10, 2023

I've tried to apply this optimization to the relayer. Here are the results:

  • Prove tree update: -31 % (from 946 ms to 653 ms)
  • Prove direct deposit: -46 % (from 25.6 s to 13.8 s)
  • RAM: +1100 mb (from 971 mb to 2076 mb)

@AllFi AllFi added the PR label Apr 11, 2023
@maikReal
Copy link

Ready, waiting for zkBob/zeropool-relayer#176 to test on staging

@AllFi
Copy link
Author

AllFi commented Jun 19, 2023

@vadimnikonov1 Could you perform regression testing on the stage to confirm that everything is functioning properly?

@vadimnikonov1
Copy link

The regression testing was successful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants