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

Use bytes representation for Certificate::aggregate_signature #9697

Merged
merged 2 commits into from
Mar 22, 2023

Conversation

jonas-lj
Copy link
Contributor

@jonas-lj jonas-lj commented Mar 22, 2023

Description

Profiling has shown that validators spend a significant amount of CPU resources deserialising the aggregate_signature field in NW's Certificate object when read from disk. This is because signatures by default are stored as compressed points, so deserialisation needs to decompress points which is a non-trivial computation. However, in most cases the signature does not need to be verified, and in these cases the binary representation suffices.

This PR replaces the aggregate_signature field in NW's Certificate object with its AsBytes representation, and the signature is only decompressed when the signature actually have to be verified. According to recently produced perf flame graphs, this could save ~2% CPU usage for validators.

Test Plan

Unit tests.

Type of Change (Check all that apply)

  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

@vercel
Copy link

vercel bot commented Mar 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Ignored Deployments
Name Status Preview Comments Updated
explorer ⬜️ Ignored (Inspect) Mar 22, 2023 at 0:11AM (UTC)
explorer-storybook ⬜️ Ignored (Inspect) Mar 22, 2023 at 0:11AM (UTC)
wallet-adapter ⬜️ Ignored (Inspect) Mar 22, 2023 at 0:11AM (UTC)

@jonas-lj jonas-lj marked this pull request as ready for review March 22, 2023 12:29
@jonas-lj jonas-lj requested review from benr-ml and removed request for kchalkias and joyqvq March 22, 2023 12:29
@@ -605,7 +606,7 @@ impl Certificate {

Ok(Certificate {
header,
aggregated_signature,
aggregated_signature: AggregateSignatureBytes::from(&aggregated_signature),
Copy link
Contributor Author

@jonas-lj jonas-lj Mar 22, 2023

Choose a reason for hiding this comment

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

It might be overkill for this problem, but we could also use the Cached object solution you proposed, @benr-ml, in order to avoid that signatures are deserialised even if they are created here and not read from disk.

@jonas-lj jonas-lj merged commit 9e0de41 into main Mar 22, 2023
@jonas-lj jonas-lj deleted the agg_sig_as_bytes branch March 22, 2023 13:16
benr-ml pushed a commit that referenced this pull request Mar 22, 2023
## Description 

Profiling has shown that validators spend a significant amount of CPU
resources deserialising the `aggregate_signature` field in NW's
`Certificate` object when read from disk. This is because signatures by
default are stored as compressed points, so deserialisation needs to
decompress points which is a non-trivial computation. However, in most
cases the signature does not need to be verified, and in these cases the
binary representation suffices.

This PR replaces the `aggregate_signature` field in NW's `Certificate`
object with its `AsBytes` representation, and the signature is only
decompressed when the signature actually have to be verified. According
to recently produced perf flame graphs, this could save ~2% CPU usage
for validators.

## Test Plan 

Unit tests.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [X] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [X] necessitate either a data wipe or data migration
danaiballa pushed a commit that referenced this pull request Mar 23, 2023
## Description 

Profiling has shown that validators spend a significant amount of CPU
resources deserialising the `aggregate_signature` field in NW's
`Certificate` object when read from disk. This is because signatures by
default are stored as compressed points, so deserialisation needs to
decompress points which is a non-trivial computation. However, in most
cases the signature does not need to be verified, and in these cases the
binary representation suffices.

This PR replaces the `aggregate_signature` field in NW's `Certificate`
object with its `AsBytes` representation, and the signature is only
decompressed when the signature actually have to be verified. According
to recently produced perf flame graphs, this could save ~2% CPU usage
for validators.

## Test Plan 

Unit tests.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [X] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [X] necessitate either a data wipe or data migration
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