1

CandyMachine program has this function, which is used extensively in the program code:

pub fn cmp_pubkeys(a: &Pubkey, b: &Pubkey) -> bool {
    sol_memcmp(a.as_ref(), b.as_ref(), PUBKEY_BYTES) == 0
}

However, I do not see, how this is different from simply using Eq trait.

1 Answer 1

2

The sol_memcmp syscall is run as native code which is both faster and cheaper than Eq/PartialEq in eBPF.

You can find the syscall implementation here.

1
  • After writing a small performance test, it seems like cmp_pubkeys function saves 11 compute units for a single call.
    – RowanStone
    Commented Jul 28, 2022 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.