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

fix(prover): speed up LWG and NWG #2661

Merged
merged 1 commit into from
Aug 16, 2024
Merged

fix(prover): speed up LWG and NWG #2661

merged 1 commit into from
Aug 16, 2024

Conversation

0xVolosnikov
Copy link
Contributor

What ❔

  • Loading of proofs for each recursive circuit is now done asynchronously
  • Each recursive circuit is now processed in a blocking thread, which speeds up serialization and other CPU-sensitive processing.

Locally, with additional artificial network delays (500 ms), a x5 speed up is observed

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zk fmt and zk lint.

Copy link
Contributor

@EmilLuta EmilLuta left a comment

Choose a reason for hiding this comment

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

Async job loading looks like the right thing. I fail to understand how moving to blocking thread helps with serialization/deserialization. Did you run tests both ways (sync/async)?

@0xVolosnikov
Copy link
Contributor Author

0xVolosnikov commented Aug 15, 2024

Did you run tests both ways (sync/async)?

Yes, the difference is noticeable. In different cases, the strategy for using threads by tokio may be different depending on blocking/non-blocking context.

tldr: afaik, async is single-threaded, but blocking tasks aren’t
https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html

@EmilLuta
Copy link
Contributor

tldr: afaik, async is single-threaded, but blocking tasks aren’t

So, my understanding is that when you start a blocking process you get a thread only for that blocking process (and more might be added, if there're more blocking asks or be blocked until the runtime can get one). I totally fail to understand what is going on behind the hood that could make it faster. @popzxc -- maybe you understand?

@0xVolosnikov
Copy link
Contributor Author

The spawned task may execute on the current thread, or it may be sent to a different thread to be executed. The specifics depend on the current Runtime configuration.

https://docs.rs/tokio/latest/tokio/task/fn.spawn.html

@popzxc
Copy link
Member

popzxc commented Aug 16, 2024

tldr: afaik, async is single-threaded, but blocking tasks aren’t

tokio::spawn will run your task on one of the runtime threads (tokio uses the same threadpool to schedule and run stuff). tokio::spawn_blocking will run your task on a dedicated blocking threadpool, which is much larger.

handle.block_on(..) will block the thread you run on, but it won't block the runtime itself, e.g. runtime will only be utilized for async stuff.

@EmilLuta
Copy link
Contributor

Discussed in DMs. I had the misconception that the runtime scheduler runs in its own thread. It runs as a regular task, therefore all blocking tasks can slow it down. We have some ser/deser in here (maybe 1ms each) and also create_leaf_witness which I haven't measured. Disregard previous comments.

@0xVolosnikov 0xVolosnikov added this pull request to the merge queue Aug 16, 2024
Merged via the queue into main with commit 6243399 Aug 16, 2024
27 checks passed
@0xVolosnikov 0xVolosnikov deleted the vv-speedup-lwg-nwg branch August 16, 2024 09:39
github-merge-queue bot pushed a commit that referenced this pull request Aug 28, 2024
🤖 I have created a release *beep* *boop*
---


##
[16.5.0](prover-v16.4.0...prover-v16.5.0)
(2024-08-28)


### Features

* **prover_cli:** Add test for status, l1 and config commands.
([#2263](#2263))
([6a2e3b0](6a2e3b0))
* **prover_cli:** Stuck status
([#2441](#2441))
([232a817](232a817))
* **prover:** Add ProverJobMonitor
([#2666](#2666))
([e22cfb6](e22cfb6))
* **prover:** parallelized memory queues simulation in BWG
([#2652](#2652))
([b4ffcd2](b4ffcd2))
* Provide easy prover setup
([#2683](#2683))
([30edda4](30edda4))


### Bug Fixes

* **prover_cli:** Remove congif file check
([#2695](#2695))
([2f456f0](2f456f0))
* **prover_cli:** Update prover cli README
([#2700](#2700))
([5a9bbb3](5a9bbb3))
* **prover:** change bucket for RAM permutation witnesses
([#2672](#2672))
([8b4cbf4](8b4cbf4))
* **prover:** fail when fri prover job is not found
([#2711](#2711))
([8776875](8776875))
* **prover:** Revert use of spawn_blocking in LWG/NWG
([#2682](#2682))
([edfcc7d](edfcc7d))
* **prover:** speed up LWG and NWG
([#2661](#2661))
([6243399](6243399))
* **vm:** Fix used bytecodes divergence
([#2741](#2741))
([923e33e](923e33e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants