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): refactor resource initialization #260

Merged
merged 11 commits into from
Jun 17, 2024
Merged

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Jun 16, 2024

Refactored the RLN module to use static resources instead of dynamically loaded resources, removing lifetime dependencies. Additionally, updated several RLN object methods and tests for compatibility with these changes.

Copy link

Benchmark for 381d801

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 843.1±9.20ns 847.5±8.74ns +0.52%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.09ns 7.5±0.31ns +1.35%
FullMerkleTree::get_subtree_root 0.9±0.01ns 0.9±0.01ns 0.00%
FullMerkleTree::override_range 1316.4±18.30ns 1298.1±11.88ns -1.39%
FullMerkleTree::set 842.5±11.48ns 850.9±10.07ns +1.00%
OptimalMerkleTree::compute_root 1003.4±10.55ns 992.2±6.70ns -1.12%
OptimalMerkleTree::delete 1004.7±15.92ns 998.7±8.80ns -0.60%
OptimalMerkleTree::get 23.6±0.19ns 23.7±0.29ns +0.42%
OptimalMerkleTree::get_empty_leaves_indices 7.2±0.22ns 7.1±0.11ns -1.39%
OptimalMerkleTree::get_subtree_root 24.1±0.34ns 23.7±0.39ns -1.66%
OptimalMerkleTree::override_range 4.1±0.06µs 4.1±0.05µs 0.00%
OptimalMerkleTree::set 1012.1±71.74ns 1000.8±9.07ns -1.12%

Copy link

Benchmark for 381d801

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 14.8±0.11ms 15.8±0.13ms +6.76%
OptimalMerkleTree::::full_height_gen 564.0±11.67µs 572.1±5.76µs +1.44%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 337.8±5.27ns 342.5±5.69ns +1.39%
Pmtree::get_empty_leaves_indices 8.7±0.14ns 8.4±0.08ns -3.45%
Pmtree::get_subtree_root 476.3±6.95ns 471.1±7.66ns -1.09%
Pmtree::override_range 233.2±5.57µs 232.3±2.96µs -0.39%
Pmtree::set 53.7±0.34µs 53.8±1.32µs +0.19%
Pmtree:delete 53.7±0.38µs 54.4±2.98µs +1.30%
Set/FullMerkleTree::::set/1 545.6±7.85µs 557.4±8.95µs +2.16%
Set/FullMerkleTree::::set/10 5.5±0.02ms 5.6±0.11ms +1.82%
Set/FullMerkleTree::::set/100 54.9±0.23ms 55.6±1.02ms +1.28%
Set/FullMerkleTree::::set_range/1 544.4±4.07µs 551.6±8.91µs +1.32%
Set/FullMerkleTree::::set_range/10 747.5±3.76µs 756.0±3.79µs +1.14%
Set/FullMerkleTree::::set_range/100 3.3±0.02ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 546.4±17.96µs 552.7±4.76µs +1.15%
Set/OptimalMerkleTree::::set/10 5.5±0.02ms 5.5±0.06ms 0.00%
Set/OptimalMerkleTree::::set/100 54.9±0.89ms 55.6±0.19ms +1.28%
Set/OptimalMerkleTree::::set_range/1 545.7±6.48µs 561.9±5.19µs +2.97%
Set/OptimalMerkleTree::::set_range/10 5.5±0.02ms 5.6±0.11ms +1.82%
Set/OptimalMerkleTree::::set_range/100 55.2±1.18ms 56.7±1.54ms +2.72%
circuit::to_verifying_key 1501.6±12.93ns 1497.6±21.73ns -0.27%
zkey::upload_from_folder 3.3±0.00s 29.9±2.69ns -100.00%

Copy link

Benchmark for cdd140c

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 844.6±14.94ns 850.3±9.55ns +0.67%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.09ns 7.4±0.05ns 0.00%
FullMerkleTree::get_subtree_root 0.9±0.01ns 0.9±0.01ns 0.00%
FullMerkleTree::override_range 1310.1±23.80ns 1300.5±13.70ns -0.73%
FullMerkleTree::set 847.7±22.27ns 851.5±7.69ns +0.45%
OptimalMerkleTree::compute_root 1010.7±29.54ns 1000.0±13.12ns -1.06%
OptimalMerkleTree::delete 1008.8±7.86ns 996.5±8.40ns -1.22%
OptimalMerkleTree::get 23.7±0.18ns 23.0±0.33ns -2.95%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.06ns 7.2±0.42ns +1.41%
OptimalMerkleTree::get_subtree_root 24.2±0.16ns 24.1±0.17ns -0.41%
OptimalMerkleTree::override_range 4.2±0.06µs 4.2±0.05µs 0.00%
OptimalMerkleTree::set 1007.8±10.27ns 998.9±8.13ns -0.88%

@rymnc rymnc changed the title chore(rln): optimize into Lazy OnceCells chore(rln): statically initialize the zkey and vk Jun 17, 2024
Copy link

Benchmark for cdd140c

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.0±0.08ms 14.9±0.09ms -0.67%
OptimalMerkleTree::::full_height_gen 563.9±6.58µs 574.3±3.10µs +1.84%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 339.3±6.72ns 335.6±6.16ns -1.09%
Pmtree::get_empty_leaves_indices 8.7±0.16ns 8.4±0.15ns -3.45%
Pmtree::get_subtree_root 478.4±15.13ns 470.3±8.42ns -1.69%
Pmtree::override_range 233.3±7.55µs 234.4±3.89µs +0.47%
Pmtree::set 53.9±1.71µs 53.7±0.66µs -0.37%
Pmtree:delete 53.6±0.63µs 53.6±0.54µs 0.00%
Set/FullMerkleTree::::set/1 543.7±6.16µs 566.0±63.62µs +4.10%
Set/FullMerkleTree::::set/10 5.4±0.02ms 5.5±0.01ms +1.85%
Set/FullMerkleTree::::set/100 54.9±0.23ms 55.5±0.14ms +1.09%
Set/FullMerkleTree::::set_range/1 544.7±4.84µs 551.6±2.52µs +1.27%
Set/FullMerkleTree::::set_range/10 747.6±8.32µs 760.3±20.48µs +1.70%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.00ms 0.00%
Set/OptimalMerkleTree::::set/1 542.1±2.42µs 553.1±3.83µs +2.03%
Set/OptimalMerkleTree::::set/10 5.5±0.01ms 5.6±0.07ms +1.82%
Set/OptimalMerkleTree::::set/100 54.9±0.18ms 55.8±0.08ms +1.64%
Set/OptimalMerkleTree::::set_range/1 542.5±4.25µs 553.9±8.24µs +2.10%
Set/OptimalMerkleTree::::set_range/10 5.5±0.02ms 5.6±0.02ms +1.82%
Set/OptimalMerkleTree::::set_range/100 54.7±0.16ms 55.6±0.12ms +1.65%
circuit::to_verifying_key 1495.8±6.46ns 1539.5±11.66ns +2.92%
zkey::upload_from_folder 3.3±0.01s 30.2±1.10ns -100.00%

Copy link

Benchmark for 86cff4a

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 843.9±15.70ns 854.0±15.88ns +1.20%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.07ns 7.4±0.12ns 0.00%
FullMerkleTree::get_subtree_root 0.9±0.03ns 0.9±0.02ns 0.00%
FullMerkleTree::override_range 1314.2±24.95ns 1316.3±20.40ns +0.16%
FullMerkleTree::set 841.3±8.18ns 846.3±14.52ns +0.59%
OptimalMerkleTree::compute_root 1012.0±21.81ns 1024.2±17.42ns +1.21%
OptimalMerkleTree::delete 1019.4±15.77ns 1011.4±11.99ns -0.78%
OptimalMerkleTree::get 25.1±0.46ns 23.8±0.75ns -5.18%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.08ns 7.1±0.08ns 0.00%
OptimalMerkleTree::get_subtree_root 24.2±0.44ns 24.3±0.29ns +0.41%
OptimalMerkleTree::override_range 4.2±0.07µs 4.2±0.25µs 0.00%
OptimalMerkleTree::set 1019.7±9.03ns 1019.1±55.48ns -0.06%

@rymnc rymnc changed the title chore(rln): statically initialize the zkey and vk chore(rln): statically initialize the resources Jun 17, 2024
Copy link

Benchmark for dbd7d4b

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 845.5±17.48ns 847.7±5.95ns +0.26%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.5±0.17ns 7.4±0.11ns -1.33%
FullMerkleTree::get_subtree_root 0.9±0.01ns 0.9±0.02ns 0.00%
FullMerkleTree::override_range 1312.9±18.17ns 1308.5±18.28ns -0.34%
FullMerkleTree::set 841.6±11.21ns 843.1±10.80ns +0.18%
OptimalMerkleTree::compute_root 1003.6±13.44ns 1007.0±9.51ns +0.34%
OptimalMerkleTree::delete 1000.7±7.47ns 1003.3±9.11ns +0.26%
OptimalMerkleTree::get 23.9±0.31ns 27.3±0.16ns +14.23%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.11ns 7.1±0.06ns 0.00%
OptimalMerkleTree::get_subtree_root 24.4±0.37ns 28.3±1.09ns +15.98%
OptimalMerkleTree::override_range 4.1±0.12µs 4.1±0.03µs 0.00%
OptimalMerkleTree::set 998.2±7.06ns 1008.2±32.99ns +1.00%

Copy link

Benchmark for 86cff4a

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.9±0.16ms 15.3±0.14ms -3.77%
OptimalMerkleTree::::full_height_gen 571.0±5.98µs 580.1±5.96µs +1.59%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 332.4±6.22ns 329.6±10.11ns -0.84%
Pmtree::get_empty_leaves_indices 8.7±0.08ns 8.7±0.16ns 0.00%
Pmtree::get_subtree_root 490.7±6.36ns 486.7±10.46ns -0.82%
Pmtree::override_range 237.5±4.78µs 235.5±3.49µs -0.84%
Pmtree::set 54.3±2.57µs 54.1±1.27µs -0.37%
Pmtree:delete 54.9±5.04µs 54.2±1.47µs -1.28%
Set/FullMerkleTree::::set/1 545.4±13.27µs 549.8±10.11µs +0.81%
Set/FullMerkleTree::::set/10 5.5±0.02ms 5.5±0.03ms 0.00%
Set/FullMerkleTree::::set/100 55.2±0.27ms 55.5±2.39ms +0.54%
Set/FullMerkleTree::::set_range/1 547.3±10.23µs 547.1±3.42µs -0.04%
Set/FullMerkleTree::::set_range/10 748.8±8.69µs 752.7±3.20µs +0.52%
Set/FullMerkleTree::::set_range/100 3.3±0.01ms 3.3±0.01ms 0.00%
Set/OptimalMerkleTree::::set/1 545.8±4.49µs 551.5±12.94µs +1.04%
Set/OptimalMerkleTree::::set/10 5.5±0.01ms 5.5±0.03ms 0.00%
Set/OptimalMerkleTree::::set/100 55.1±0.15ms 55.5±0.19ms +0.73%
Set/OptimalMerkleTree::::set_range/1 545.4±4.93µs 552.3±3.48µs +1.27%
Set/OptimalMerkleTree::::set_range/10 5.5±0.02ms 5.5±0.02ms 0.00%
Set/OptimalMerkleTree::::set_range/100 55.0±0.16ms 55.6±0.36ms +1.09%
circuit::to_verifying_key 1544.1±42.43ns 1509.2±13.34ns -2.26%
zkey::upload_from_folder 3.3±0.01s 30.2±2.42ns -100.00%

Copy link

Benchmark for dbd7d4b

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 14.0±0.60ms 14.7±0.10ms +5.00%
OptimalMerkleTree::::full_height_gen 568.4±5.83µs 575.5±9.18µs +1.25%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 325.0±6.28ns 342.6±5.94ns +5.42%
Pmtree::get_empty_leaves_indices 8.7±0.15ns 8.7±0.26ns 0.00%
Pmtree::get_subtree_root 474.1±3.66ns 483.9±9.18ns +2.07%
Pmtree::override_range 239.2±9.10µs 241.2±6.38µs +0.84%
Pmtree::set 54.0±0.56µs 53.8±0.33µs -0.37%
Pmtree:delete 54.8±0.58µs 53.9±0.33µs -1.64%
Set/FullMerkleTree::::set/1 547.6±4.53µs 547.7±7.42µs +0.02%
Set/FullMerkleTree::::set/10 5.4±0.01ms 5.5±0.02ms +1.85%
Set/FullMerkleTree::::set/100 54.5±0.24ms 55.3±0.22ms +1.47%
Set/FullMerkleTree::::set_range/1 541.5±7.72µs 549.4±5.64µs +1.46%
Set/FullMerkleTree::::set_range/10 744.4±6.72µs 754.3±6.55µs +1.33%
Set/FullMerkleTree::::set_range/100 3.3±0.02ms 3.3±0.00ms 0.00%
Set/OptimalMerkleTree::::set/1 551.3±4.90µs 552.0±11.16µs +0.13%
Set/OptimalMerkleTree::::set/10 5.5±0.03ms 5.6±0.02ms +1.82%
Set/OptimalMerkleTree::::set/100 55.7±0.16ms 55.6±0.25ms -0.18%
Set/OptimalMerkleTree::::set_range/1 552.4±5.68µs 553.0±7.83µs +0.11%
Set/OptimalMerkleTree::::set_range/10 5.6±0.03ms 5.5±0.03ms -1.79%
Set/OptimalMerkleTree::::set_range/100 55.8±0.43ms 55.4±0.18ms -0.72%
circuit::to_verifying_key 1530.4±10.60ns 1510.9±17.15ns -1.27%
zkey::upload_from_folder 3.3±0.00s 30.3±3.49ns -100.00%

Copy link

Benchmark for f8e98f8

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 847.9±16.10ns 843.6±12.71ns -0.51%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.03ns 7.4±0.06ns 0.00%
FullMerkleTree::get_subtree_root 0.9±0.01ns 0.9±0.02ns 0.00%
FullMerkleTree::override_range 1315.1±21.09ns 1311.2±15.07ns -0.30%
FullMerkleTree::set 860.5±57.54ns 841.9±8.73ns -2.16%
OptimalMerkleTree::compute_root 1005.5±20.33ns 1012.0±16.54ns +0.65%
OptimalMerkleTree::delete 1012.2±24.24ns 1009.6±16.33ns -0.26%
OptimalMerkleTree::get 23.7±0.37ns 23.9±0.28ns +0.84%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.12ns 7.1±0.08ns 0.00%
OptimalMerkleTree::get_subtree_root 24.3±0.44ns 24.4±0.34ns +0.41%
OptimalMerkleTree::override_range 4.2±0.06µs 4.2±0.32µs 0.00%
OptimalMerkleTree::set 1011.3±14.29ns 1014.4±63.76ns +0.31%

Copy link

Benchmark for f4d15c1

Click to view benchmark
Test Base PR %
FullMerkleTree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::delete 848.1±11.22ns 866.5±8.61ns +2.17%
FullMerkleTree::get 0.0±0.00ns 0.0±0.00ns NaN%
FullMerkleTree::get_empty_leaves_indices 7.4±0.12ns 7.4±0.11ns 0.00%
FullMerkleTree::get_subtree_root 0.9±0.02ns 0.9±0.01ns 0.00%
FullMerkleTree::override_range 1298.3±11.14ns 1303.1±35.07ns +0.37%
FullMerkleTree::set 850.8±5.31ns 864.7±6.57ns +1.63%
OptimalMerkleTree::compute_root 995.5±14.27ns 1013.2±25.64ns +1.78%
OptimalMerkleTree::delete 998.3±16.51ns 1028.1±55.90ns +2.99%
OptimalMerkleTree::get 23.2±0.18ns 23.0±0.45ns -0.86%
OptimalMerkleTree::get_empty_leaves_indices 7.1±0.05ns 7.1±0.13ns 0.00%
OptimalMerkleTree::get_subtree_root 24.0±0.34ns 24.1±0.57ns +0.42%
OptimalMerkleTree::override_range 4.2±0.17µs 4.2±0.13µs 0.00%
OptimalMerkleTree::set 996.3±8.30ns 1023.9±34.67ns +2.77%

Copy link

Benchmark for f8e98f8

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 14.4±0.07ms 14.9±0.51ms +3.47%
OptimalMerkleTree::::full_height_gen 578.6±9.48µs 572.8±8.28µs -1.00%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 328.0±4.95ns 335.3±13.73ns +2.23%
Pmtree::get_empty_leaves_indices 8.7±0.09ns 8.7±0.08ns 0.00%
Pmtree::get_subtree_root 469.7±8.28ns 487.3±30.98ns +3.75%
Pmtree::override_range 238.0±4.80µs 231.1±2.98µs -2.90%
Pmtree::set 53.9±0.96µs 53.5±0.35µs -0.74%
Pmtree:delete 53.7±1.04µs 53.5±0.54µs -0.37%
Set/FullMerkleTree::::set/1 548.2±7.37µs 548.1±5.02µs -0.02%
Set/FullMerkleTree::::set/10 5.5±0.02ms 5.5±0.02ms 0.00%
Set/FullMerkleTree::::set/100 54.7±0.19ms 55.5±0.18ms +1.46%
Set/FullMerkleTree::::set_range/1 546.7±7.55µs 550.5±7.81µs +0.70%
Set/FullMerkleTree::::set_range/10 746.1±5.66µs 753.0±8.53µs +0.92%
Set/FullMerkleTree::::set_range/100 3.3±0.12ms 3.3±0.19ms 0.00%
Set/OptimalMerkleTree::::set/1 548.7±7.91µs 548.7±6.19µs 0.00%
Set/OptimalMerkleTree::::set/10 5.5±0.26ms 5.5±0.02ms 0.00%
Set/OptimalMerkleTree::::set/100 55.3±3.06ms 55.5±0.31ms +0.36%
Set/OptimalMerkleTree::::set_range/1 546.1±4.25µs 551.4±7.95µs +0.97%
Set/OptimalMerkleTree::::set_range/10 5.4±0.03ms 5.5±0.01ms +1.85%
Set/OptimalMerkleTree::::set_range/100 54.9±0.58ms 55.3±0.14ms +0.73%
circuit::to_verifying_key 1562.3±25.72ns 1507.5±10.34ns -3.51%
zkey::upload_from_folder 3.3±0.01s 3.3±0.01s 0.00%

Copy link

Benchmark for f4d15c1

Click to view benchmark
Test Base PR %
FullMerkleTree::::full_height_gen 15.1±0.17ms 15.6±0.53ms +3.31%
OptimalMerkleTree::::full_height_gen 576.0±66.83µs 568.7±6.01µs -1.27%
Pmtree::compute_root 0.0±0.00ns 0.0±0.00ns NaN%
Pmtree::get 358.3±6.70ns 333.5±6.11ns -6.92%
Pmtree::get_empty_leaves_indices 8.7±0.14ns 8.7±0.21ns 0.00%
Pmtree::get_subtree_root 475.4±7.28ns 506.3±4.34ns +6.50%
Pmtree::override_range 234.4±3.46µs 234.5±10.29µs +0.04%
Pmtree::set 53.7±0.60µs 53.7±0.44µs 0.00%
Pmtree:delete 53.6±0.49µs 53.7±0.43µs +0.19%
Set/FullMerkleTree::::set/1 544.6±5.48µs 551.7±4.61µs +1.30%
Set/FullMerkleTree::::set/10 5.4±0.02ms 5.5±0.01ms +1.85%
Set/FullMerkleTree::::set/100 54.8±0.25ms 55.4±0.21ms +1.09%
Set/FullMerkleTree::::set_range/1 545.7±21.62µs 550.5±7.47µs +0.88%
Set/FullMerkleTree::::set_range/10 748.3±6.03µs 751.8±10.58µs +0.47%
Set/FullMerkleTree::::set_range/100 3.3±0.00ms 3.3±0.02ms 0.00%
Set/OptimalMerkleTree::::set/1 544.4±2.57µs 550.7±8.21µs +1.16%
Set/OptimalMerkleTree::::set/10 5.5±0.02ms 5.5±0.05ms 0.00%
Set/OptimalMerkleTree::::set/100 55.0±0.17ms 55.6±0.27ms +1.09%
Set/OptimalMerkleTree::::set_range/1 547.7±2.34µs 550.8±6.10µs +0.57%
Set/OptimalMerkleTree::::set_range/10 5.5±0.03ms 5.5±0.03ms 0.00%
Set/OptimalMerkleTree::::set_range/100 55.0±0.10ms 55.5±0.19ms +0.91%
circuit::to_verifying_key 1512.5±9.15ns N/A N/A
vk::vk_from_ark_serialized 1503.2±7.69ns N/A N/A
zkey::upload_from_folder 3.3±0.00s N/A N/A
zkey::zkey_from_raw 3.3±0.00s N/A N/A

@rymnc rymnc changed the title chore(rln): statically initialize the resources chore(rln): refactor resource initialization Jun 17, 2024
@rymnc rymnc marked this pull request as ready for review June 17, 2024 07:00
@rymnc rymnc requested a review from seemenkina June 17, 2024 07:00
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

@rymnc rymnc merged commit d8f813b into master Jun 17, 2024
10 checks passed
@rymnc rymnc deleted the include-file-instead-of-dir branch June 17, 2024 08:13
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