-
Notifications
You must be signed in to change notification settings - Fork 11
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
Simplify debug naming of variables in constraints #435
base: master
Are you sure you want to change the base?
Conversation
query_instance
's API
I would say this change definitely worth to explore as we always looking for improve the readibility. But honestly wrapping them in And we can expect it might be help to make binary size smaller if we gonna distribute prover binary into IOT device. So I would suggest before clear out the thoughts, please on hold this issue and spend effort on other more urgent milestone task. We definitely look back into this issue sometime, and prove we can achieve same effect without "closure" then it will be super nice |
Closures aren't free to create and pass around, even if you don't use them. Yes, a clever optimizing compiler can perhaps remove them, but the same techniques would allow the compiler also remove the
Well, the PR branch has about 3% smaller binary sizes than what's currently in This is PR mainly for readability, and to avoid our typical cargo culting and tendency to unnecessarily overcomplicate things. |
a8c4894
to
d152c03
Compare
@lispc If you want to quickly get PRs into master, here's one that's been sitting for a while. It simplifies our code, without any compromise in performance. |
I dont think this fit the long sitting for a while PR, especially from my comment above. The closure style didn't bring up readibility issue to me, while with that in key setup/release build, we can eliminate those debugging message. I vote +1 for current bellman style and think we should build idea based on that unless there is a more convinced method to me. |
Yes, you can get rid of these messages in either style. And the optimiser has a slightly easier job with the plain string than when unnecessarily wrapping it in a closure. In the common case now we are just passing a reference to a string that's a constant in the binary. Instead of all the heavy machinery necessary to make closures work. About readability: it's useful to use simple mechanisms when simple mechanisms are sufficient. Amongst other benefits, this lets the presence of a complicated mechanism alert the reader that something complicated is going on. Basically, the only reason this is still in the code is because of status quo bias. I hope no one would really suggest going from the simpler system to the overly complicated version we have right now. |
Instead of passing an
FnOnce
closure with no arguments, we just pass the name itself.It looks like we copied the old convention from other R1CS proving systems like bellman. But we always execute our closure, rendering the whole exercise pointless, while they only do execute theirs in debug contexts. (Thanks to Ming for the historic context!)
(And even for bellman, it's unlikely they actually get anything out of the extra complexity: making and passing closures around is a lot of work at runtime. And an optimising compiler that can remove an unused closure can also much easier remove an unused string.)
I ran some benchmarks. The change ever so slightly speeds up compilation and runtime, and decreases the size of our binaries.
On
master
:On this branch:
This benchmark is just for fun, the PR is for readability.