Election-Tech-Initiative / electionguard-cpp

A C++ implementation of ElectionGuard specification focused on encryption components.
https://www.electionguard.vote/
MIT License
23 stars 26 forks source link

Ballot Encryption Speed Issue #252

Closed SteveMaier-IRT closed 2 years ago

SteveMaier-IRT commented 2 years ago

Is there an existing issue for this?

Current Behavior

When constructing the CiphertextElectionContext object using constructor in step 1 below, it is taking 6-7 seconds to encrypt a ballot. When I use the constructor in step 2, it is taking 20 seconds to encrypt a ballot.

  1. var context = new CiphertextElectionContext( 1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash);

  2. var context = new CiphertextElectionContext(“read json string from context.js file.”)

This happens on a test program running .NET 4.8 and loading the nuget package version 0.1.6. Running the test program in x64 or x86 version both produce a delay of about 2.5x slower times using the JSON constructor.

Expected Behavior

Using any of the constructors for the CiphertextElectionContext should provide the same time frame for encrypting data.

Steps To Reproduce

A new benchmark test was created to help determine if the issue was in the C++ or in the C# code. The encrypt ballot benchmark was used and the JSON constructor was used instead of the parameterized one. This showed that with all of the steps and the data objects the same that the timing was consistently 2.5x the faster speed. A test app was created to do the same things and test in either 32-bit or 64-bit and the same results were shown as well.

32-bit Tests Parameters - 3658 ms JSON - 9641 ms

64-bit Tests Parameters - 774 ms JSON - 1928 ms

The benchmark test showed the same ratio from the two constructors.

Parameters - 100 ms JSON - 260 ms

Environment

- OS:

Anything else?

No response

colleenirt commented 2 years ago

We will discuss this with the Extended Standup team on Thursday

colleenirt commented 2 years ago

The encryption step is taking longer if you use the second constructor - ~2.5x slower.

colleenirt commented 2 years ago

@SteveMaier-IRT when you have a moment, please add the details for "how to benchmark" to this issue