lang: Remove unnecessary clone in account exit routine (#3139)

This commit is contained in:
acheron 2024-07-31 22:27:30 +02:00 committed by GitHub
parent 3f945f682c
commit f6a8042c40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 181 additions and 180 deletions

View File

@ -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

View File

@ -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

View File

@ -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)).
---

View File

@ -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)?;

View File

@ -933,96 +933,96 @@
"solanaVersion": "1.18.17",
"result": {
"binarySize": {
"bench": 790256
"bench": 787968
},
"computeUnits": {
"accountInfo1": 574,
"accountInfo2": 900,
"accountInfo4": 1562,
"accountInfo8": 2958,
"accountEmptyInit1": 5019,
"accountEmpty1": 650,
"accountEmptyInit2": 9675,
"accountEmpty2": 1016,
"accountEmptyInit4": 18492,
"accountEmpty4": 1741,
"accountEmptyInit8": 36164,
"accountEmpty8": 3194,
"accountSizedInit1": 5115,
"accountSized1": 691,
"accountSizedInit2": 9839,
"accountSized2": 1070,
"accountSizedInit4": 18854,
"accountSized4": 1835,
"accountSizedInit8": 36779,
"accountSized8": 3358,
"accountUnsizedInit1": 5232,
"accountUnsized1": 748,
"accountUnsizedInit2": 10116,
"accountUnsized2": 1166,
"accountUnsizedInit4": 19299,
"accountUnsized4": 2005,
"accountUnsizedInit8": 37375,
"accountUnsized8": 3680,
"boxedAccountEmptyInit1": 5121,
"boxedAccountEmpty1": 741,
"boxedAccountEmptyInit2": 9782,
"boxedAccountEmpty2": 1126,
"boxedAccountEmptyInit4": 18646,
"boxedAccountEmpty4": 1887,
"boxedAccountEmptyInit8": 36396,
"boxedAccountEmpty8": 3436,
"boxedAccountSizedInit1": 5202,
"boxedAccountSized1": 781,
"boxedAccountSizedInit2": 9931,
"boxedAccountSized2": 1181,
"boxedAccountSizedInit4": 18913,
"boxedAccountSized4": 1975,
"boxedAccountSizedInit8": 36916,
"boxedAccountSized8": 3594,
"boxedAccountUnsizedInit1": 5313,
"boxedAccountUnsized1": 840,
"boxedAccountUnsizedInit2": 10123,
"boxedAccountUnsized2": 1278,
"boxedAccountUnsizedInit4": 19273,
"boxedAccountUnsized4": 2143,
"boxedAccountUnsizedInit8": 37612,
"boxedAccountUnsized8": 3904,
"boxedInterfaceAccountMint1": 1503,
"boxedInterfaceAccountMint2": 2424,
"boxedInterfaceAccountMint4": 4257,
"boxedInterfaceAccountMint8": 7951,
"boxedInterfaceAccountToken1": 2199,
"boxedInterfaceAccountToken2": 3804,
"boxedInterfaceAccountToken4": 7005,
"boxedInterfaceAccountToken8": 13435,
"interfaceAccountMint1": 1627,
"interfaceAccountMint2": 2789,
"interfaceAccountMint4": 5111,
"interfaceAccountMint8": 9750,
"interfaceAccountToken1": 2297,
"interfaceAccountToken2": 4097,
"interfaceAccountToken4": 7693,
"interface1": 775,
"interface2": 924,
"interface4": 1215,
"interface8": 1800,
"program1": 783,
"program2": 928,
"program4": 1211,
"program8": 1780,
"signer1": 780,
"signer2": 1075,
"signer4": 1658,
"signer8": 2827,
"systemAccount1": 803,
"systemAccount2": 1109,
"systemAccount4": 1714,
"systemAccount8": 2927,
"uncheckedAccount1": 786,
"uncheckedAccount2": 1062,
"uncheckedAccount4": 1605,
"uncheckedAccount8": 2700
"accountInfo1": 573,
"accountInfo2": 899,
"accountInfo4": 1561,
"accountInfo8": 2957,
"accountEmptyInit1": 4976,
"accountEmpty1": 649,
"accountEmptyInit2": 9590,
"accountEmpty2": 1015,
"accountEmptyInit4": 18323,
"accountEmpty4": 1740,
"accountEmptyInit8": 35827,
"accountEmpty8": 3193,
"accountSizedInit1": 5070,
"accountSized1": 690,
"accountSizedInit2": 9750,
"accountSized2": 1069,
"accountSizedInit4": 18677,
"accountSized4": 1834,
"accountSizedInit8": 36426,
"accountSized8": 3357,
"accountUnsizedInit1": 5190,
"accountUnsized1": 747,
"accountUnsizedInit2": 10033,
"accountUnsized2": 1165,
"accountUnsizedInit4": 19134,
"accountUnsized4": 2004,
"accountUnsizedInit8": 37046,
"accountUnsized8": 3679,
"boxedAccountEmptyInit1": 5078,
"boxedAccountEmpty1": 740,
"boxedAccountEmptyInit2": 9697,
"boxedAccountEmpty2": 1125,
"boxedAccountEmptyInit4": 18477,
"boxedAccountEmpty4": 1886,
"boxedAccountEmptyInit8": 36059,
"boxedAccountEmpty8": 3435,
"boxedAccountSizedInit1": 5157,
"boxedAccountSized1": 780,
"boxedAccountSizedInit2": 9842,
"boxedAccountSized2": 1180,
"boxedAccountSizedInit4": 18736,
"boxedAccountSized4": 1974,
"boxedAccountSizedInit8": 36563,
"boxedAccountSized8": 3593,
"boxedAccountUnsizedInit1": 5271,
"boxedAccountUnsized1": 839,
"boxedAccountUnsizedInit2": 10040,
"boxedAccountUnsized2": 1277,
"boxedAccountUnsizedInit4": 19108,
"boxedAccountUnsized4": 2142,
"boxedAccountUnsizedInit8": 37283,
"boxedAccountUnsized8": 3903,
"boxedInterfaceAccountMint1": 1502,
"boxedInterfaceAccountMint2": 2423,
"boxedInterfaceAccountMint4": 4256,
"boxedInterfaceAccountMint8": 7950,
"boxedInterfaceAccountToken1": 2198,
"boxedInterfaceAccountToken2": 3803,
"boxedInterfaceAccountToken4": 7004,
"boxedInterfaceAccountToken8": 13434,
"interfaceAccountMint1": 1626,
"interfaceAccountMint2": 2788,
"interfaceAccountMint4": 5110,
"interfaceAccountMint8": 9749,
"interfaceAccountToken1": 2296,
"interfaceAccountToken2": 4096,
"interfaceAccountToken4": 7692,
"interface1": 774,
"interface2": 923,
"interface4": 1214,
"interface8": 1799,
"program1": 782,
"program2": 927,
"program4": 1210,
"program8": 1779,
"signer1": 779,
"signer2": 1074,
"signer4": 1657,
"signer8": 2826,
"systemAccount1": 802,
"systemAccount2": 1108,
"systemAccount4": 1713,
"systemAccount8": 2926,
"uncheckedAccount1": 785,
"uncheckedAccount2": 1061,
"uncheckedAccount4": 1604,
"uncheckedAccount8": 2699
},
"stackMemory": {
"account_info1": 144,