Taproot sig message#3
Merged
RCasatta merged 3 commits intoRCasatta:taproot_sig_messagefrom Aug 31, 2021
Merged
Conversation
There was a question whether this is equally performant. There are multiple good reasons why it should be: 1. `get_or_insert_with` is marked `#[inline]` 2. Any good optimizer will inline a function that is used exactly once 3. 1 and 2 conclude that the closure will get inlined 4. Computing self.tx can then be moved to the only branch where it is required. 5. Even if get_or_insert_with didn't get optimized, which is extremely unlikely, the `tx` field is at the beginning of the struct and it probably has pointer alignment (`Deref` suggests it's a pointer). Alignment larger than pointer is not used, so we can expect the fields to be ordered as-defined. (This is not guaranteed by Rust but there's not good reason to change the order in this case.) We can assume that offset to tx is zero in most cases which means no computation is actually needed so the expression before closure is no-op short of passing it into the closure as an argument. At the time of writing `#[inline]` can be seen at https://doc.rust-lang.org/src/core/option.rs.html#933
This refactors the code to make it possible to use `get_or_insert_with` instead of unwrapping in `segwit_cache()`. To achieve it `common_cache` is refactored into two functions: one taking only the required borrows and the original calling the new one. `segwit_cache` then calls the new function so that borrows are OK. Apart from removing unwrap, this avoids calling `common_cache` multiple times.
Author
|
Thinking about it a bit more, if cache miss is very rare we could make the closures |
Owner
|
I am in PTO at the moment but I did a quick look and I think I am going to merge this. Just I am not doing it now because I need some time to dedicate to this and other comments in the PR... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes replace
unwrap()withget_or_insert_with()in cache methods. The commits explain why performance shouldn't be lost.