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

chore(rln): use ark serialized verification key for faster serde #259

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Jun 13, 2024

Pre-processed the verification key in a similar manner to rln_final.arkzkey, and replaced the verification_key.json with it, and all references to it

Copy link

Benchmark for 46b1959

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 851.9±30.20ns 842.2±12.60ns -1.14%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.07ns 7.5±0.26ns +1.35%
FullMerkleTree::get_subtree_root 0.9±0.04ns 0.9±0.03ns 0.00%
FullMerkleTree::override_range 1304.0±19.77ns 1311.4±24.73ns +0.57%
FullMerkleTree::set 850.5±10.24ns 843.1±11.56ns -0.87%
OptimalMerkleTree::compute_root 993.4±9.03ns 1000.8±16.58ns +0.74%
OptimalMerkleTree::delete 994.1±16.70ns 1007.9±28.22ns +1.39%
OptimalMerkleTree::get 23.0±0.20ns 23.7±0.29ns +3.04%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.11ns 7.1±0.06ns 0.00%
OptimalMerkleTree::get_subtree_root 24.3±0.50ns 24.3±0.24ns 0.00%
OptimalMerkleTree::override_range 4.1±0.07µs 4.1±0.09µs 0.00%
OptimalMerkleTree::set 992.5±11.34ns 1007.1±23.29ns +1.47%

Copy link

Benchmark for 9ce478b

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 844.9±15.89ns 871.0±11.49ns +3.09%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.13ns 7.4±0.07ns 0.00%
FullMerkleTree::get_subtree_root 0.9±0.01ns 0.9±0.03ns 0.00%
FullMerkleTree::override_range 1313.0±12.58ns 1298.4±12.67ns -1.11%
FullMerkleTree::set 841.8±10.52ns 847.2±10.10ns +0.64%
OptimalMerkleTree::compute_root 1022.3±15.05ns 1009.8±17.26ns -1.22%
OptimalMerkleTree::delete 1020.8±10.34ns 1009.2±13.44ns -1.14%
OptimalMerkleTree::get 23.9±0.34ns 23.0±0.32ns -3.77%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.12ns 7.1±0.17ns 0.00%
OptimalMerkleTree::get_subtree_root 24.4±0.40ns 24.1±0.28ns -1.23%
OptimalMerkleTree::override_range 4.2±0.06µs 4.4±0.16µs +4.76%
OptimalMerkleTree::set 1017.9±12.02ns 1012.3±12.51ns -0.55%

Copy link

Benchmark for 46b1959

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 16.1±0.12ms 14.6±0.11ms -9.32%
OptimalMerkleTree::::full_height_gen 576.8±6.43µs 566.5±6.80µs -1.79%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 332.3±5.60ns 330.1±5.08ns -0.66%
Pmtree::get_empty_leaves_indices 8.4±0.07ns 8.7±0.14ns +3.57%
Pmtree::get_subtree_root 470.6±8.50ns 473.2±9.71ns +0.55%
Pmtree::override_range 242.3±7.34µs 233.8±3.13µs -3.51%
Pmtree::set 54.9±3.02µs 53.7±0.53µs -2.19%
Pmtree:delete 54.5±0.48µs 53.8±0.56µs -1.28%
Set/FullMerkleTree::::set/1 570.2±5.60µs 544.2±8.53µs -4.56%
Set/FullMerkleTree::::set/10 5.6±0.01ms 5.5±0.01ms -1.79%
Set/FullMerkleTree::::set/100 55.6±0.22ms 54.6±0.08ms -1.80%
Set/FullMerkleTree::::set_range/1 566.1±9.06µs 543.1±3.20µs -4.06%
Set/FullMerkleTree::::set_range/10 756.8±6.42µs 744.7±3.75µs -1.60%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.2±0.01ms -3.03%
Set/OptimalMerkleTree::::set/1 555.1±7.81µs 545.1±6.45µs -1.80%
Set/OptimalMerkleTree::::set/10 5.6±0.02ms 5.5±0.23ms -1.79%
Set/OptimalMerkleTree::::set/100 55.9±0.11ms 54.8±0.12ms -1.97%
Set/OptimalMerkleTree::::set_range/1 557.6±5.97µs 539.6±6.02µs -3.23%
Set/OptimalMerkleTree::::set_range/10 5.6±0.01ms 5.5±0.02ms -1.79%
Set/OptimalMerkleTree::::set_range/100 55.7±0.43ms 55.0±0.13ms -1.26%
circuit::to_verifying_key 1450.1±7.74µs 1516.3±8.70ns -99.90%
zkey::upload_from_folder 3.3±0.00s 3.3±0.01s 0.00%

Copy link

Benchmark for 9ce478b

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 14.6±0.08ms 15.6±0.49ms +6.85%
OptimalMerkleTree::::full_height_gen 574.9±6.46µs 567.5±4.35µs -1.29%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 328.0±6.95ns 332.8±3.52ns +1.46%
Pmtree::get_empty_leaves_indices 8.4±0.16ns 8.7±0.11ns +3.57%
Pmtree::get_subtree_root 482.1±9.54ns 471.9±8.45ns -2.12%
Pmtree::override_range 242.9±4.30µs 231.1±3.64µs -4.86%
Pmtree::set 54.6±0.79µs 54.1±3.27µs -0.92%
Pmtree:delete 54.5±0.54µs 53.6±0.41µs -1.65%
Set/FullMerkleTree::::set/1 551.1±13.02µs 541.5±3.91µs -1.74%
Set/FullMerkleTree::::set/10 5.5±0.02ms 5.5±0.02ms 0.00%
Set/FullMerkleTree::::set/100 55.6±0.14ms 54.8±0.23ms -1.44%
Set/FullMerkleTree::::set_range/1 552.5±6.99µs 544.3±9.65µs -1.48%
Set/FullMerkleTree::::set_range/10 757.5±7.50µs 746.2±6.48µs -1.49%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.02ms 0.00%
Set/OptimalMerkleTree::::set/1 552.3±4.78µs 541.8±4.94µs -1.90%
Set/OptimalMerkleTree::::set/10 5.6±0.03ms 5.5±0.01ms -1.79%
Set/OptimalMerkleTree::::set/100 55.6±0.17ms 54.7±0.18ms -1.62%
Set/OptimalMerkleTree::::set_range/1 552.8±1.90µs 545.5±7.17µs -1.32%
Set/OptimalMerkleTree::::set_range/10 5.6±0.03ms 5.5±0.01ms -1.79%
Set/OptimalMerkleTree::::set_range/100 55.8±1.62ms 54.7±0.23ms -1.97%
circuit::to_verifying_key 1447.8±6.84µs 1516.6±12.23ns -99.90%
zkey::upload_from_folder 3.3±0.00s 3.3±0.01s 0.00%

use std::path::Path;

// Here we benchmark how long the deserialization of the
// verifying_key takes, only testing the json => verifying_key conversion,
// and skipping conversion from bytes => string => serde_json::Value
pub fn vk_deserialize_benchmark(c: &mut Criterion) {
let vk = RESOURCES_DIR.get_file(Path::new(VK_FILENAME)).unwrap();
let vk = vk.contents_utf8().unwrap();
let json: Value = serde_json::from_str(vk).unwrap();
let vk = vk.contents();

c.bench_function("circuit::to_verifying_key", |b| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

leaving the bench_function name as-is to compare. will fix in following PR

@rymnc rymnc marked this pull request as ready for review June 13, 2024 10:45
@rymnc rymnc requested a review from seemenkina June 13, 2024 10:45
Copy link

Benchmark for 9380d29

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 856.3±12.20ns 841.4±14.00ns -1.74%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.07ns 7.4±0.11ns 0.00%
FullMerkleTree::get_subtree_root 0.9±0.01ns 0.9±0.02ns 0.00%
FullMerkleTree::override_range 1345.8±12.30ns 1312.0±21.81ns -2.51%
FullMerkleTree::set 851.9±10.39ns 847.2±7.55ns -0.55%
OptimalMerkleTree::compute_root 1032.5±10.10ns 1004.1±12.86ns -2.75%
OptimalMerkleTree::delete 1009.6±14.10ns 1011.6±19.82ns +0.20%
OptimalMerkleTree::get 23.9±0.27ns 23.7±0.29ns -0.84%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.13ns 7.1±0.07ns 0.00%
OptimalMerkleTree::get_subtree_root 24.4±0.30ns 24.3±0.23ns -0.41%
OptimalMerkleTree::override_range 4.2±0.04µs 4.2±0.08µs 0.00%
OptimalMerkleTree::set 1006.1±7.52ns 1010.6±13.33ns +0.45%

Copy link
Contributor

@seemenkina seemenkina left a comment

Choose a reason for hiding this comment

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

LGTM

to_verifying_key(&json)
// Computes the verification key from a bytes vector containing pre-processed ark-serialized verification key
// uncompressed, unchecked
pub fn vk_from_slice(data: &[u8]) -> Result<VerifyingKey<Curve>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we need other function name? Like vk_from_ark_serilized or vk_from_ark_json

because I was expecting something along the lines of what we did when we pulled specific bytes from the slice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 400d9f1

Copy link

Benchmark for 9380d29

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.2±0.19ms 15.4±0.46ms +1.32%
OptimalMerkleTree::::full_height_gen 579.2±27.65µs 570.9±9.29µs -1.43%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 356.5±6.95ns 323.1±4.75ns -9.37%
Pmtree::get_empty_leaves_indices 8.4±0.19ns 8.7±0.16ns +3.57%
Pmtree::get_subtree_root 480.8±8.36ns 477.3±7.00ns -0.73%
Pmtree::override_range 232.9±4.53µs 233.1±3.67µs +0.09%
Pmtree::set 54.9±2.82µs 53.9±0.60µs -1.82%
Pmtree:delete 54.4±0.35µs 53.7±0.51µs -1.29%
Set/FullMerkleTree::::set/1 552.7±6.94µs 546.0±7.20µs -1.21%
Set/FullMerkleTree::::set/10 5.6±0.02ms 5.5±0.02ms -1.79%
Set/FullMerkleTree::::set/100 55.7±0.24ms 54.8±0.23ms -1.62%
Set/FullMerkleTree::::set_range/1 554.1±17.99µs 547.8±7.24µs -1.14%
Set/FullMerkleTree::::set_range/10 758.1±5.32µs 747.1±4.67µs -1.45%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 555.1±3.75µs 545.4±2.66µs -1.75%
Set/OptimalMerkleTree::::set/10 5.6±0.02ms 5.5±0.02ms -1.79%
Set/OptimalMerkleTree::::set/100 55.8±0.21ms 54.9±0.13ms -1.61%
Set/OptimalMerkleTree::::set_range/1 555.1±7.27µs 548.8±7.53µs -1.13%
Set/OptimalMerkleTree::::set_range/10 5.5±0.02ms 5.5±0.02ms 0.00%
Set/OptimalMerkleTree::::set_range/100 55.7±0.55ms 54.9±0.15ms -1.44%
circuit::to_verifying_key 1450.8±6.51µs 1521.0±25.82ns -99.90%
zkey::upload_from_folder 3.3±0.00s 3.3±0.01s 0.00%

Copy link

Benchmark for 0138fdb

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 842.4±7.71ns 848.1±9.47ns +0.68%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.5±0.29ns 7.4±0.08ns -1.33%
FullMerkleTree::get_subtree_root 0.9±0.02ns 0.9±0.01ns 0.00%
FullMerkleTree::override_range 1307.1±20.09ns 1305.9±12.41ns -0.09%
FullMerkleTree::set 842.1±7.48ns 848.6±6.15ns +0.77%
OptimalMerkleTree::compute_root 1007.3±19.95ns 1020.3±17.27ns +1.29%
OptimalMerkleTree::delete 1011.0±12.77ns 1023.7±8.49ns +1.26%
OptimalMerkleTree::get 23.7±0.31ns 23.8±0.73ns +0.42%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.08ns 7.1±0.12ns 0.00%
OptimalMerkleTree::get_subtree_root 24.3±0.23ns 24.4±0.63ns +0.41%
OptimalMerkleTree::override_range 4.2±0.07µs 4.2±0.19µs 0.00%
OptimalMerkleTree::set 1010.5±13.59ns 1025.4±28.64ns +1.47%

Copy link

Benchmark for 0138fdb

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 13.9±0.07ms 14.7±0.13ms +5.76%
OptimalMerkleTree::::full_height_gen 575.2±9.25µs 567.3±7.74µs -1.37%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 331.0±4.99ns 332.5±3.58ns +0.45%
Pmtree::get_empty_leaves_indices 8.4±0.08ns 8.7±0.17ns +3.57%
Pmtree::get_subtree_root 471.5±4.48ns 478.5±6.87ns +1.48%
Pmtree::override_range 230.0±3.58µs 229.7±4.40µs -0.13%
Pmtree::set 54.6±0.38µs 53.7±0.35µs -1.65%
Pmtree:delete 54.9±0.92µs 53.9±0.59µs -1.82%
Set/FullMerkleTree::::set/1 553.5±7.20µs 547.1±3.36µs -1.16%
Set/FullMerkleTree::::set/10 5.6±0.02ms 5.5±0.04ms -1.79%
Set/FullMerkleTree::::set/100 55.7±0.24ms 54.8±0.13ms -1.62%
Set/FullMerkleTree::::set_range/1 557.3±3.83µs 543.7±3.83µs -2.44%
Set/FullMerkleTree::::set_range/10 758.7±4.98µs 745.6±4.66µs -1.73%
Set/FullMerkleTree::::set_range/100 3.3±0.00ms 3.3±0.04ms 0.00%
Set/OptimalMerkleTree::::set/1 553.5±7.12µs 542.6±5.22µs -1.97%
Set/OptimalMerkleTree::::set/10 5.6±0.05ms 5.5±0.02ms -1.79%
Set/OptimalMerkleTree::::set/100 55.7±1.20ms 55.0±0.55ms -1.26%
Set/OptimalMerkleTree::::set_range/1 552.5±5.42µs 543.4±14.03µs -1.65%
Set/OptimalMerkleTree::::set_range/10 5.5±0.02ms 5.5±0.02ms 0.00%
Set/OptimalMerkleTree::::set_range/100 55.7±0.18ms 54.9±0.22ms -1.44%
circuit::to_verifying_key 1451.2±5.25µs 1515.7±9.66ns -99.90%
zkey::upload_from_folder 3.3±0.00s 3.3±0.00s 0.00%

@rymnc rymnc merged commit c6493bd into master Jun 14, 2024
10 checks passed
@rymnc rymnc deleted the use-serde-deser branch June 14, 2024 05:33
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.

2 participants