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

Better serialization of binary values and singletons #844

Merged
merged 8 commits into from
Jan 9, 2025

Conversation

iliailia
Copy link
Collaborator

@iliailia iliailia commented Dec 19, 2024

Instead of sending single values as VecRingT, we serialize them as individual elements. This is especially beneficial when doing bitwise comparisons, where sending a single bit required 5 bytes of serialized data. This change reduces it to 2. For u64, the size is reduced from 20 to 10 bytes.
In addition, this PR replaces bincode with bitcode, which is about 15% more compact for the NetworkValue enum. The total gain is about 37%.

Communication cost per party to insert 1 vector into a database of size 1 (i.e., one call to eval_distance and one call to less_than) is given below.

Before:

Stats for party Identity("alice"):
Bytes sent: 1389
Bytes received: 1389
Stats for party Identity("bob"):
Bytes sent: 1389
Bytes received: 1437
Stats for party Identity("charlie"):
Bytes sent: 1417
Bytes received: 1369

After:

Stats for party Identity("alice"):
Bytes sent: 885
Bytes received: 885
Stats for party Identity("bob"):
Bytes sent: 885
Bytes received: 907
Stats for party Identity("charlie"):
Bytes sent: 896
Bytes received: 874

bitcode is slower than bincode, which is reflected in a 5-25% increase in running time for both insertion and search.

gr_ready_made_hnsw/gr-big-hnsw-insertions/1
                        time:   [2.3032 ms 2.3137 ms 2.3299 ms]
                        change: [+6.1174% +8.1775% +10.549%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/1
                        time:   [3.3832 ms 3.4097 ms 3.4656 ms]
                        change: [+7.6982% +9.7017% +11.805%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/10
                        time:   [85.330 ms 86.775 ms 88.262 ms]
                        change: [+2.7516% +4.7590% +6.7136%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/10
                        time:   [53.284 ms 53.762 ms 54.214 ms]
                        change: [+6.1638% +10.074% +13.611%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/100
                        time:   [1.2600 s 1.2681 s 1.2769 s]
                        change: [+1.9064% +4.8861% +7.8922%] (p = 0.01 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/100
                        time:   [775.21 ms 786.06 ms 797.46 ms]
                        change: [+10.597% +15.231% +19.069%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/1000
                        time:   [3.4237 s 3.4414 s 3.4590 s]
                        change: [+6.5509% +8.5298% +10.339%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/1000
                        time:   [2.0689 s 2.1586 s 2.2907 s]
                        change: [+10.130% +15.345% +23.125%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/10000
                        time:   [6.9597 s 7.1282 s 7.3122 s]
                        change: [+14.125% +16.964% +20.189%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/10000
                        time:   [3.7279 s 3.8948 s 4.0742 s]
                        change: [+13.594% +19.064% +25.207%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/100000
                        time:   [9.0077 s 9.4853 s 9.9697 s]
                        change: [+19.589% +25.218% +31.718%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/100000
                        time:   [4.6592 s 4.8944 s 5.1631 s]
                        change: [+8.8328% +14.471% +20.709%] (p = 0.00 < 0.05)
                        Performance has regressed.

@iliailia iliailia requested review from bgillesp and dkales December 19, 2024 16:32
iris-mpc-cpu/src/network/value.rs Show resolved Hide resolved
iris-mpc-cpu/src/network/value.rs Outdated Show resolved Hide resolved
iris-mpc-cpu/src/network/value.rs Outdated Show resolved Hide resolved
iris-mpc-cpu/src/network/value.rs Outdated Show resolved Hide resolved
@iliailia
Copy link
Collaborator Author

iliailia commented Jan 8, 2025

Guys, sorry for changing this PR almost entirely. I added a custom serialization that brought the performance back and even gained a bit more. The current benchmarking results are the following

Communication:

Stats for party Identity("bob"):
Rounds: 53
Bytes sent: 845
Bytes received: 875
Stats for party Identity("charlie"):
Rounds: 53
Bytes sent: 862
Bytes received: 832
Stats for party Identity("alice"):
Rounds: 53
Bytes sent: 845
Bytes received: 845

Running time (in comparison to the one above):

gr_ready_made_hnsw/gr-big-hnsw-insertions/1
                        time:   [2.0494 ms 2.0767 ms 2.1024 ms]
gr_ready_made_hnsw/gr-big-hnsw-searches/1
                        time:   [3.0304 ms 3.0676 ms 3.0967 ms]
gr_ready_made_hnsw/gr-big-hnsw-insertions/10
                        time:   [74.011 ms 74.983 ms 76.775 ms]
gr_ready_made_hnsw/gr-big-hnsw-searches/10
                        time:   [45.616 ms 46.257 ms 47.247 ms]
gr_ready_made_hnsw/gr-big-hnsw-insertions/100
                        time:   [1.0943 s 1.1229 s 1.1492 s]
                        change: [-25.943% -23.699% -21.898%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/100
                        time:   [662.72 ms 687.23 ms 712.31 ms]
                        change: [-26.357% -23.826% -20.564%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/1000
                        time:   [2.9798 s 3.0148 s 3.0564 s]
                        change: [-25.662% -24.840% -23.886%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/1000
                        time:   [1.8064 s 1.8388 s 1.8704 s]
                        change: [-22.091% -20.095% -18.120%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/10000
                        time:   [5.6744 s 5.7518 s 5.8269 s]
                        change: [-23.766% -22.686% -21.621%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/10000
                        time:   [3.0832 s 3.1271 s 3.1760 s]
                        change: [-25.487% -24.297% -23.200%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/100000
                        time:   [6.7998 s 6.8641 s 6.9288 s]
                        change: [-26.099% -24.969% -23.805%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/100000
                        time:   [3.4343 s 3.5064 s 3.5838 s]
                        change: [-31.274% -29.707% -27.821%] (p = 0.00 < 0.05)

@dkales
Copy link
Collaborator

dkales commented Jan 8, 2025

Guys, sorry for changing this PR almost entirely. I added a custom serialization that brought the performance back and even gained a bit more. The current benchmarking results are the following

Communication:

Stats for party Identity("bob"):
Rounds: 53
Bytes sent: 845
Bytes received: 875
Identity("charlie") Open bin bytes: 1
Stats for party Identity("charlie"):
Rounds: 53
Bytes sent: 862
Bytes received: 832
Stats for party Identity("alice"):
Rounds: 53
Bytes sent: 845
Bytes received: 845

Running time (in comparison to the one above):

gr_ready_made_hnsw/gr-big-hnsw-insertions/1
                        time:   [2.0494 ms 2.0767 ms 2.1024 ms]
gr_ready_made_hnsw/gr-big-hnsw-searches/1
                        time:   [3.0304 ms 3.0676 ms 3.0967 ms]
gr_ready_made_hnsw/gr-big-hnsw-insertions/10
                        time:   [74.011 ms 74.983 ms 76.775 ms]
gr_ready_made_hnsw/gr-big-hnsw-searches/10
                        time:   [45.616 ms 46.257 ms 47.247 ms]
gr_ready_made_hnsw/gr-big-hnsw-insertions/100
                        time:   [1.0943 s 1.1229 s 1.1492 s]
                        change: [-25.943% -23.699% -21.898%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/100
                        time:   [662.72 ms 687.23 ms 712.31 ms]
                        change: [-26.357% -23.826% -20.564%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/1000
                        time:   [2.9798 s 3.0148 s 3.0564 s]
                        change: [-25.662% -24.840% -23.886%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/1000
                        time:   [1.8064 s 1.8388 s 1.8704 s]
                        change: [-22.091% -20.095% -18.120%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/10000
                        time:   [5.6744 s 5.7518 s 5.8269 s]
                        change: [-23.766% -22.686% -21.621%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/10000
                        time:   [3.0832 s 3.1271 s 3.1760 s]
                        change: [-25.487% -24.297% -23.200%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-insertions/100000
                        time:   [6.7998 s 6.8641 s 6.9288 s]
                        change: [-26.099% -24.969% -23.805%] (p = 0.00 < 0.05)
gr_ready_made_hnsw/gr-big-hnsw-searches/100000
                        time:   [3.4343 s 3.5064 s 3.5838 s]
                        change: [-31.274% -29.707% -27.821%] (p = 0.00 < 0.05)

nice, have a few more suggestions that might help a bit more with perf

Copy link
Collaborator

@bgillesp bgillesp left a comment

Choose a reason for hiding this comment

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

Nice! See minor comments, but looks good to me if Daniel has finished suggesting optimizations.

iris-mpc-cpu/Cargo.toml Outdated Show resolved Hide resolved
iris-mpc-cpu/src/network/value.rs Show resolved Hide resolved
@@ -18,20 +17,250 @@ pub enum NetworkValue {
}

impl NetworkValue {
fn get_descriptor_byte(&self) -> u8 {
match self {
NetworkValue::PrfKey(_) => 0x01,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these descriptor bytes start at 1 because the network byte stream looks for 0 to indicate EOF or something similar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking to leave it for some special message, e.g., "abort"

@iliailia iliailia merged commit d31df96 into main Jan 9, 2025
13 checks passed
@iliailia iliailia deleted the ilia/reduce-comm-and-many branch January 9, 2025 14:38
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