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

Cache contract inputs in the VM #770

Merged
merged 4 commits into from
Jun 15, 2024
Merged

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Jun 15, 2024

Closes #761

Updated benchmark to cover worst case FuelLabs/fuel-core#1973

Checklist

  • If performance characteristic of an instruction change, update gas costs as well or make a follow-up PR for that

Before requesting review

  • I have reviewed the code myself

@xgreenx xgreenx requested a review from a team June 15, 2024 09:58
@xgreenx xgreenx self-assigned this Jun 15, 2024
panic_context,
}
}

/// Checks that the contract is declared in the transaction inputs.
pub fn check(&mut self, contract: &ContractId) -> SimpleResult<()> {
if !self.tx_input_contracts.any(|input| input == contract) {
if !self.input_contracts.contains(contract) {
Copy link
Member

Choose a reason for hiding this comment

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

Essentially, the idea of this PR is making this lookup more performant? Is that right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep

@@ -41,6 +45,33 @@ where
) -> Result<(), RuntimeError<S::DataError>> {
tx.prepare_init_execute();
self.tx = tx;
self.input_contracts = self
Copy link
Member

Choose a reason for hiding this comment

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

So we might be taking a bit of a hit on performance because of this, but at least its constant time and not an attack vector?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we calculate it each time now during initialization and later all related operations will be fast

MitchTurner
MitchTurner previously approved these changes Jun 15, 2024
@xgreenx xgreenx added this pull request to the merge queue Jun 15, 2024
Merged via the queue into master with commit 1192221 Jun 15, 2024
39 checks passed
@xgreenx xgreenx deleted the feature/cache-contract-inputs branch June 15, 2024 19:58
@xgreenx xgreenx mentioned this pull request Jun 15, 2024
xgreenx added a commit to FuelLabs/fuel-core that referenced this pull request Jun 15, 2024
#1973)

Covers new behavior from FuelLabs/fuel-vm#770

### Before requesting review
- [x] I have reviewed the code myself
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.

Verify the impact of inputs/outputs on the performance of the VM
2 participants