Skip to content

perf(protocol): optimize AccountCode equality comparison#2725

Open
giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov:fix/account-code-partial-eq
Open

perf(protocol): optimize AccountCode equality comparison#2725
giwaov wants to merge 1 commit into0xMiden:nextfrom
giwaov:fix/account-code-partial-eq

Conversation

@giwaov
Copy link
Copy Markdown

@giwaov giwaov commented Apr 4, 2026

Summary

Optimize the PartialEq implementation for AccountCode by comparing commitment and procedures instead of the full MastForest.

Rationale

The existing implementation compares the entire MastForest (which can be large and expensive to compare) alongside the procedures list. Since the commitment is a sequential hash of all procedure MAST roots, two AccountCode instances with identical commitments and procedures are guaranteed to represent the same account interface. Comparing the MastForest is therefore redundant.

This resolves the TODO comment that was already in the code suggesting this change.

Changes

crates/miden-protocol/src/account/code/mod.rs:

  • Changed PartialEq to compare self.commitment and self.procedures instead of self.mast and self.procedures

Test plan

  • cargo check -p miden-protocol passes
  • cargo clippy -p miden-protocol -- -D warnings passes
  • The Eq impl is unchanged and still derived from the updated PartialEq
  • The Ord impl already compares by commitment only, so ordering and equality are now aligned

Closes #2429

Compare AccountCode instances by commitment and procedures instead of
comparing the full MastForest. Two AccountCode instances with identical
procedure sets will always have identical commitments, so comparing the
MastForest is redundant and expensive.

Closes 0xMiden#2429
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.

Optimize AccountCode equality comparison performance

1 participant