Skip to content

Commit

Permalink
lang: Remove unnecessary clone in account exit routine (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Jul 31, 2024
1 parent 3f945f6 commit f6a8042
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 180 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Fix using `owner` constraint with `Box`ed accounts ([#3087](https://github.com/coral-xyz/anchor/pull/3087)).
- lang: Add a sanity check for unimplemented token extensions ([#3090](https://github.com/coral-xyz/anchor/pull/3090)).
- cli: Skip IDL checks if `--no-idl` option is passed ([#3093](https://github.com/coral-xyz/anchor/pull/3093)).
- lang: Remove unnecessary clone in account exit routine ([#3139](https://github.com/coral-xyz/anchor/pull/3139)).

### Breaking

Expand Down
6 changes: 3 additions & 3 deletions bench/BINARY_SIZE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ The programs and their tests are located in [/tests/bench](https://github.com/co

Solana version: 1.18.17

| Program | Binary Size | - |
| ------- | ----------- | ------------------- |
| bench | 790,256 | 🟢 **-752 (0.10%)** |
| Program | Binary Size | - |
| ------- | ----------- | --------------------- |
| bench | 787,968 | 🟢 **-3,040 (0.38%)** |

### Notable changes

Expand Down
175 changes: 88 additions & 87 deletions bench/COMPUTE_UNITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,97 +18,98 @@ Solana version: 1.18.17

| Instruction | Compute Units | - |
| --------------------------- | ------------- | -------------------- |
| accountInfo1 | 574 | 🟢 **-27 (4.49%)** |
| accountInfo2 | 900 | 🟢 **-23 (2.49%)** |
| accountInfo4 | 1,562 | 🟢 **-21 (1.33%)** |
| accountInfo8 | 2,958 | 🟢 **-17 (0.57%)** |
| accountEmptyInit1 | 5,019 | 🟢 **-15 (0.30%)** |
| accountEmpty1 | 650 | 🟢 **-2 (0.31%)** |
| accountEmptyInit2 | 9,675 | 🟢 **-12 (0.12%)** |
| accountEmpty2 | 1,016 | - |
| accountEmptyInit4 | 18,492 | 🟢 **-9 (0.05%)** |
| accountEmpty4 | 1,741 | 🔴 **+4 (0.23%)** |
| accountEmptyInit8 | 36,164 | 🟢 **-5 (0.01%)** |
| accountEmpty8 | 3,194 | 🔴 **+8 (0.25%)** |
| accountSizedInit1 | 5,115 | 🔴 **+9 (0.18%)** |
| accountSized1 | 691 | 🔴 **+23 (3.44%)** |
| accountSizedInit2 | 9,839 | 🔴 **+11 (0.11%)** |
| accountSized2 | 1,070 | 🔴 **+24 (2.29%)** |
| accountSizedInit4 | 18,854 | 🔴 **+17 (0.09%)** |
| accountSized4 | 1,835 | 🔴 **+28 (1.55%)** |
| accountSizedInit8 | 36,779 | 🔴 **+18 (0.05%)** |
| accountSized8 | 3,358 | 🔴 **+32 (0.96%)** |
| accountUnsizedInit1 | 5,232 | 🔴 **+33 (0.63%)** |
| accountUnsized1 | 748 | 🔴 **+46 (6.55%)** |
| accountUnsizedInit2 | 10,116 | 🔴 **+38 (0.38%)** |
| accountUnsized2 | 1,166 | 🔴 **+50 (4.48%)** |
| accountUnsizedInit4 | 19,299 | 🔴 **+40 (0.21%)** |
| accountUnsized4 | 2,005 | 🔴 **+52 (2.66%)** |
| accountUnsizedInit8 | 37,375 | 🔴 **+44 (0.12%)** |
| accountUnsized8 | 3,680 | 🔴 **+54 (1.49%)** |
| boxedAccountEmptyInit1 | 5,121 | 🔴 **+57 (1.13%)** |
| boxedAccountEmpty1 | 741 | 🔴 **+70 (10.43%)** |
| boxedAccountEmptyInit2 | 9,782 | 🔴 **+61 (0.63%)** |
| boxedAccountEmpty2 | 1,126 | 🔴 **+74 (7.03%)** |
| boxedAccountEmptyInit4 | 18,646 | 🔴 **+64 (0.34%)** |
| boxedAccountEmpty4 | 1,887 | 🔴 **+76 (4.20%)** |
| boxedAccountEmptyInit8 | 36,396 | 🔴 **+67 (0.18%)** |
| boxedAccountEmpty8 | 3,436 | 🔴 **+79 (2.35%)** |
| boxedAccountSizedInit1 | 5,202 | 🔴 **+83 (1.62%)** |
| boxedAccountSized1 | 781 | 🔴 **+95 (13.85%)** |
| boxedAccountSizedInit2 | 9,931 | 🔴 **+86 (0.87%)** |
| boxedAccountSized2 | 1,181 | 🔴 **+96 (8.85%)** |
| boxedAccountSizedInit4 | 18,913 | 🔴 **+88 (0.47%)** |
| boxedAccountSized4 | 1,975 | 🔴 **+101 (5.39%)** |
| boxedAccountSizedInit8 | 36,916 | 🔴 **+92 (0.25%)** |
| boxedAccountSized8 | 3,594 | 🔴 **+104 (2.98%)** |
| boxedAccountUnsizedInit1 | 5,313 | 🔴 **+106 (2.04%)** |
| boxedAccountUnsized1 | 840 | 🔴 **+119 (16.50%)** |
| boxedAccountUnsizedInit2 | 10,123 | 🔴 **+108 (1.08%)** |
| boxedAccountUnsized2 | 1,278 | 🔴 **+121 (10.46%)** |
| boxedAccountUnsizedInit4 | 19,273 | 🔴 **+113 (0.59%)** |
| boxedAccountUnsized4 | 2,143 | 🔴 **+124 (6.14%)** |
| boxedAccountUnsizedInit8 | 37,612 | 🔴 **+116 (0.31%)** |
| boxedAccountUnsized8 | 3,904 | 🔴 **+128 (3.39%)** |
| boxedInterfaceAccountMint1 | 1,503 | 🔴 **+131 (9.55%)** |
| boxedInterfaceAccountMint2 | 2,424 | 🔴 **+131 (5.71%)** |
| boxedInterfaceAccountMint4 | 4,257 | 🔴 **+136 (3.30%)** |
| boxedInterfaceAccountMint8 | 7,951 | 🔴 **+140 (1.79%)** |
| boxedInterfaceAccountToken1 | 2,199 | 🔴 **+143 (6.96%)** |
| boxedInterfaceAccountToken2 | 3,804 | 🔴 **+144 (3.93%)** |
| boxedInterfaceAccountToken4 | 7,005 | 🔴 **+147 (2.14%)** |
| boxedInterfaceAccountToken8 | 13,435 | 🔴 **+151 (1.14%)** |
| interfaceAccountMint1 | 1,627 | 🔴 **+155 (10.53%)** |
| interfaceAccountMint2 | 2,789 | 🔴 **+158 (6.01%)** |
| interfaceAccountMint4 | 5,111 | 🔴 **+160 (3.23%)** |
| interfaceAccountMint8 | 9,750 | 🔴 **+162 (1.69%)** |
| interfaceAccountToken1 | 2,297 | 🔴 **+167 (7.84%)** |
| interfaceAccountToken2 | 4,097 | 🔴 **+169 (4.30%)** |
| interfaceAccountToken4 | 7,693 | 🔴 **+172 (2.29%)** |
| interface1 | 775 | 🔴 **+175 (29.17%)** |
| interface2 | 924 | 🔴 **+179 (24.03%)** |
| interface4 | 1,215 | 🔴 **+182 (17.62%)** |
| interface8 | 1,800 | 🔴 **+184 (11.39%)** |
| program1 | 783 | 🔴 **+187 (31.38%)** |
| program2 | 928 | 🔴 **+191 (25.92%)** |
| program4 | 1,211 | 🔴 **+192 (18.84%)** |
| program8 | 1,780 | 🔴 **+196 (12.37%)** |
| signer1 | 780 | 🔴 **+200 (34.48%)** |
| signer2 | 1,075 | 🔴 **+203 (23.28%)** |
| signer4 | 1,658 | 🔴 **+204 (14.03%)** |
| signer8 | 2,827 | 🔴 **+209 (7.98%)** |
| systemAccount1 | 803 | 🔴 **+211 (35.64%)** |
| systemAccount2 | 1,109 | 🔴 **+215 (24.05%)** |
| systemAccount4 | 1,714 | 🔴 **+217 (14.50%)** |
| systemAccount8 | 2,927 | 🔴 **+220 (8.13%)** |
| uncheckedAccount1 | 786 | 🔴 **+223 (39.61%)** |
| uncheckedAccount2 | 1,062 | 🔴 **+226 (27.03%)** |
| uncheckedAccount4 | 1,605 | 🔴 **+227 (16.47%)** |
| uncheckedAccount8 | 2,700 | 🔴 **+232 (9.40%)** |
| accountInfo1 | 573 | 🟢 **-28 (4.66%)** |
| accountInfo2 | 899 | 🟢 **-24 (2.60%)** |
| accountInfo4 | 1,561 | 🟢 **-22 (1.39%)** |
| accountInfo8 | 2,957 | 🟢 **-18 (0.61%)** |
| accountEmptyInit1 | 4,976 | 🟢 **-58 (1.15%)** |
| accountEmpty1 | 649 | 🟢 **-3 (0.46%)** |
| accountEmptyInit2 | 9,590 | 🟢 **-97 (1.00%)** |
| accountEmpty2 | 1,015 | 🟢 **-1 (0.10%)** |
| accountEmptyInit4 | 18,323 | 🟢 **-178 (0.96%)** |
| accountEmpty4 | 1,740 | 🔴 **+3 (0.17%)** |
| accountEmptyInit8 | 35,827 | 🟢 **-342 (0.95%)** |
| accountEmpty8 | 3,193 | 🔴 **+7 (0.22%)** |
| accountSizedInit1 | 5,070 | 🟢 **-36 (0.71%)** |
| accountSized1 | 690 | 🔴 **+22 (3.29%)** |
| accountSizedInit2 | 9,750 | 🟢 **-78 (0.79%)** |
| accountSized2 | 1,069 | 🔴 **+23 (2.20%)** |
| accountSizedInit4 | 18,677 | 🟢 **-160 (0.85%)** |
| accountSized4 | 1,834 | 🔴 **+27 (1.49%)** |
| accountSizedInit8 | 36,426 | 🟢 **-335 (0.91%)** |
| accountSized8 | 3,357 | 🔴 **+31 (0.93%)** |
| accountUnsizedInit1 | 5,190 | 🟢 **-9 (0.17%)** |
| accountUnsized1 | 747 | 🔴 **+45 (6.41%)** |
| accountUnsizedInit2 | 10,033 | 🟢 **-45 (0.45%)** |
| accountUnsized2 | 1,165 | 🔴 **+49 (4.39%)** |
| accountUnsizedInit4 | 19,134 | 🟢 **-125 (0.65%)** |
| accountUnsized4 | 2,004 | 🔴 **+51 (2.61%)** |
| accountUnsizedInit8 | 37,046 | 🟢 **-285 (0.76%)** |
| accountUnsized8 | 3,679 | 🔴 **+53 (1.46%)** |
| boxedAccountEmptyInit1 | 5,078 | 🔴 **+14 (0.28%)** |
| boxedAccountEmpty1 | 740 | 🔴 **+69 (10.28%)** |
| boxedAccountEmptyInit2 | 9,697 | 🟢 **-24 (0.25%)** |
| boxedAccountEmpty2 | 1,125 | 🔴 **+73 (6.94%)** |
| boxedAccountEmptyInit4 | 18,477 | 🟢 **-105 (0.57%)** |
| boxedAccountEmpty4 | 1,886 | 🔴 **+75 (4.14%)** |
| boxedAccountEmptyInit8 | 36,059 | 🟢 **-270 (0.74%)** |
| boxedAccountEmpty8 | 3,435 | 🔴 **+78 (2.32%)** |
| boxedAccountSizedInit1 | 5,157 | 🔴 **+38 (0.74%)** |
| boxedAccountSized1 | 780 | 🔴 **+94 (13.70%)** |
| boxedAccountSizedInit2 | 9,842 | 🟢 **-3 (0.03%)** |
| boxedAccountSized2 | 1,180 | 🔴 **+95 (8.76%)** |
| boxedAccountSizedInit4 | 18,736 | 🟢 **-89 (0.47%)** |
| boxedAccountSized4 | 1,974 | 🔴 **+100 (5.34%)** |
| boxedAccountSizedInit8 | 36,563 | 🟢 **-261 (0.71%)** |
| boxedAccountSized8 | 3,593 | 🔴 **+103 (2.95%)** |
| boxedAccountUnsizedInit1 | 5,271 | 🔴 **+64 (1.23%)** |
| boxedAccountUnsized1 | 839 | 🔴 **+118 (16.37%)** |
| boxedAccountUnsizedInit2 | 10,040 | 🔴 **+25 (0.25%)** |
| boxedAccountUnsized2 | 1,277 | 🔴 **+120 (10.37%)** |
| boxedAccountUnsizedInit4 | 19,108 | 🟢 **-52 (0.27%)** |
| boxedAccountUnsized4 | 2,142 | 🔴 **+123 (6.09%)** |
| boxedAccountUnsizedInit8 | 37,283 | 🟢 **-213 (0.57%)** |
| boxedAccountUnsized8 | 3,903 | 🔴 **+127 (3.36%)** |
| boxedInterfaceAccountMint1 | 1,502 | 🔴 **+130 (9.48%)** |
| boxedInterfaceAccountMint2 | 2,423 | 🔴 **+130 (5.67%)** |
| boxedInterfaceAccountMint4 | 4,256 | 🔴 **+135 (3.28%)** |
| boxedInterfaceAccountMint8 | 7,950 | 🔴 **+139 (1.78%)** |
| boxedInterfaceAccountToken1 | 2,198 | 🔴 **+142 (6.91%)** |
| boxedInterfaceAccountToken2 | 3,803 | 🔴 **+143 (3.91%)** |
| boxedInterfaceAccountToken4 | 7,004 | 🔴 **+146 (2.13%)** |
| boxedInterfaceAccountToken8 | 13,434 | 🔴 **+150 (1.13%)** |
| interfaceAccountMint1 | 1,626 | 🔴 **+154 (10.46%)** |
| interfaceAccountMint2 | 2,788 | 🔴 **+157 (5.97%)** |
| interfaceAccountMint4 | 5,110 | 🔴 **+159 (3.21%)** |
| interfaceAccountMint8 | 9,749 | 🔴 **+161 (1.68%)** |
| interfaceAccountToken1 | 2,296 | 🔴 **+166 (7.79%)** |
| interfaceAccountToken2 | 4,096 | 🔴 **+168 (4.28%)** |
| interfaceAccountToken4 | 7,692 | 🔴 **+171 (2.27%)** |
| interface1 | 774 | 🔴 **+174 (29.00%)** |
| interface2 | 923 | 🔴 **+178 (23.89%)** |
| interface4 | 1,214 | 🔴 **+181 (17.52%)** |
| interface8 | 1,799 | 🔴 **+183 (11.32%)** |
| program1 | 782 | 🔴 **+186 (31.21%)** |
| program2 | 927 | 🔴 **+190 (25.78%)** |
| program4 | 1,210 | 🔴 **+191 (18.74%)** |
| program8 | 1,779 | 🔴 **+195 (12.31%)** |
| signer1 | 779 | 🔴 **+199 (34.31%)** |
| signer2 | 1,074 | 🔴 **+202 (23.17%)** |
| signer4 | 1,657 | 🔴 **+203 (13.96%)** |
| signer8 | 2,826 | 🔴 **+208 (7.94%)** |
| systemAccount1 | 802 | 🔴 **+210 (35.47%)** |
| systemAccount2 | 1,108 | 🔴 **+214 (23.94%)** |
| systemAccount4 | 1,713 | 🔴 **+216 (14.43%)** |
| systemAccount8 | 2,926 | 🔴 **+219 (8.09%)** |
| uncheckedAccount1 | 785 | 🔴 **+222 (39.43%)** |
| uncheckedAccount2 | 1,061 | 🔴 **+225 (26.91%)** |
| uncheckedAccount4 | 1,604 | 🔴 **+226 (16.40%)** |
| uncheckedAccount8 | 2,699 | 🔴 **+231 (9.36%)** |

### Notable changes

- lang: Update `dispatch` function to support dynamic discriminators ([#3104](https://github.com/coral-xyz/anchor/pull/3104)).
- lang: Remove unnecessary clone in account exit routine ([#3139](https://github.com/coral-xyz/anchor/pull/3139)).

---

Expand Down
3 changes: 1 addition & 2 deletions lang/src/accounts/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Account<'a, T> {
) -> Result<()> {
// Only persist if the owner is the current program and the account is not closed.
if expected_owner == program_id && !crate::common::is_closed(self.info) {
let info = self.to_account_info();
let mut data = info.try_borrow_mut_data()?;
let mut data = self.info.try_borrow_mut_data()?;
let dst: &mut [u8] = &mut data;
let mut writer = BpfWriter::new(dst);
self.account.try_serialize(&mut writer)?;
Expand Down
Loading

0 comments on commit f6a8042

Please sign in to comment.