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

Optimise attestation_pk to not re-construct public keys so many times #24

Open
thomaseizinger opened this issue Mar 25, 2022 · 1 comment

Comments

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Mar 25, 2022

Here is a flamegraph for a contract setup with the taker of itchysats at the time of writing this issue:

flamegraph.zip

From that flamegraph, we can see that we spend a whopping 12% of our CPU time in the attestation_pk function. 2/3 of that (8% in total) are spent with parsing public keys.

I made a dirty patch of maia and itchysats where I replaced all usages of schnorrsig::Publickey with secp256k1_zkp::Publickey. Here is the flamegraph of that:

flamegraph.zip

In that flamegraph, attestation_pk takes only 4.5% of the entire CPU time but all of that is spent in combining keys (which is that actual job of that function).

In a nutshell, this means we can easily knock off 8% of CPU cycles for each contract-setup / rollover. From skimming the logs, the gain is about 2 seconds in execution time: From 11s to 9s between the logs Exchanged setup parameters and Contract setup was completed.

I didn't submit the patches because:

a) I think using x-only is more correct because that is what olivia is returning
b) Unfortunately, it is unlikely that secp256k1 will support the required arithmetic to not convert the keys: rust-bitcoin/rust-secp256k1#405
c) The patches are hacky

@thomaseizinger
Copy link
Contributor Author

cc @luckysori @klochowicz You might be interested in these findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant