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

Convert dyn to generics in `verified_blob_content #1517

Merged
merged 6 commits into from
Nov 26, 2024

Conversation

yaziciahmet
Copy link
Contributor

@yaziciahmet yaziciahmet commented Nov 25, 2024

Description

Replaces dyn with generics as its slightly more efficient.

Linked Issues

  • Fixes # (issue, if applicable)
  • Related to # (issue)

Testing

Describe how these changes were tested. If you've added new features, have you added unit tests?

Docs

Describe where this code is documented. If it changes a documented interface, have the docs been updated?

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.3%. Comparing base (0494407) to head (e1994f5).
Report is 2 commits behind head on nightly.

Additional details and impacted files
Files with missing lines Coverage Δ
crates/bitcoin-da/src/verifier.rs 46.6% <100.0%> (-39.4%) ⬇️

... and 10 files with indirect coverage changes

@kpp
Copy link
Contributor

kpp commented Nov 25, 2024

It's questionable since &dyn generates less code and generics monomorphize code for every unique T.

I would really love to have a test for prover/verifier to calculate exact cycle count for a block with a fixed content inside. It will help us a lot in cases like this.

Anyway, I am not against this PR.

@rakanalh
Copy link
Contributor

It's questionable since &dyn generates less code and generics monomorphize code for every unique T.

I would really love to have a test for prover/verifier to calculate exact cycle count for a block with a fixed content inside. It will help us a lot in cases like this.

Anyway, I am not against this PR.

This would firstly affect the compile time aspect of the code & binary size. Secondly, I think that using generics would allow the compiler to better optimize the code after monomorphization takes place.

Copy link
Member

@eyusufatik eyusufatik left a comment

Choose a reason for hiding this comment

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

since this function will only actually take in bitcoin blob txs, we won't be generating more code with templates. only reason we went dyn or T is we are implementing a trait.

so I guess a little bit of better runtime performance is ok.

@yaziciahmet
Copy link
Contributor Author

I also optimized the verified_blob_content method in this pr:

  1. removed clone, as the blob is already owned byte iterator, we can just return the reference
  2. no need for advance, as full_data method is already called in native, and the verified data is populated in CountedBufReader.

Step 2 has something unnecessary that is happenning right now. current impl of BlobWithSender is that it has its blob as CountedBufReader, which holds 1 reader, and 1 vec which is being read into, and anytime advance (or full_data) is called, it reads from the reader into the vec. the thing is, we always use another vector as the reader into this CountedBufReader, meaning that we just pass 2x the same data unnecessarily into the zk, and we have no partial reads whatsoever. we can just replace CountedBufReader with vec. but this is relatively tricky to do since BlobWithSender is part of the trait type definition of the BitcoinSpec, and versioning is going to be very uncomfortable.

@yaziciahmet yaziciahmet merged commit d7f5037 into nightly Nov 26, 2024
14 of 15 checks passed
@yaziciahmet yaziciahmet deleted the yaziciahmet/replace-dyn-with-generics branch November 26, 2024 13:06
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.

4 participants