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

Refactor append_tx_effects_for_blob to avoid duplicated computation #11058

Closed
TomAFrench opened this issue Jan 6, 2025 · 5 comments
Closed
Assignees

Comments

@TomAFrench
Copy link
Member

See #11037 (comment)

@MirandaWood
Copy link
Contributor

Did you address this in #11213 or is there more that can be done to dedupe some code?
Not sure whether we could merge get_tx_effects_hash_inputand get_tx_effects_hash_input_helper and call it twice, once constrained once unconstrained, and have some if std::runtime::is_unconstrained() clauses?

@TomAFrench
Copy link
Member Author

TomAFrench commented Feb 7, 2025

I don't know if I'd say that PR closed this issue but at some point we'll hit diminishing returns.

We can definitely wrap the constraining logic in if !std::runtime::is_unconstrained() to improve simulation speed.

The main potential optimization I can see is that it's probably worth making an unconstrained helper for this function (and potentially removing the usage of boundedVec?).

fn get_all_update_requests_for_tx_effects(
all_public_data_update_requests: [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX],
) -> [PublicDataWrite; MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX] {
let mut all_update_requests: BoundedVec<PublicDataWrite, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX> =
BoundedVec::new();
for update_request in all_public_data_update_requests {
if !is_empty(update_request) {
all_update_requests.push(update_request);
}
}
all_update_requests.storage()
}

@MirandaWood
Copy link
Contributor

Yeah, that function costs a ton of gates. I'm not sure whether we still even need it (see comment // TODO remove this? The avm should be returning public data writes left aligned.), so I think that's why it's untouched. @sirasistant do you know if we can remove this function?

@sirasistant
Copy link
Collaborator

Yes I think we can just remove it! I think in the past we had that because we had 63 updates from the avm and then we always put the fee write in position 63. I think now everything should come left aligned, and if not, it's a bug elsewhere!

MirandaWood added a commit that referenced this issue Feb 13, 2025
Refactors the `append_tx_effects_for_blob` function for #11058:

- Removes expensive public data update gathering function
- Combines the two `get_effects` functions into one to avoid doubling
code

Should probably be merged after #11686, since that would be easier to
merge into this PR rather than vice versa.
@TomAFrench
Copy link
Member Author

I think we can close this now. The remaining duplicated computation is just encoding the prefixes which would be harming readability for negligible benefit.

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

No branches or pull requests

3 participants