Pārlūkot izejas kodu

lang: `Box` the inner enums of `anchor_lang::error::Error` (#2600)

Co-authored-by: acheron <acheroncrypto@gmail.com>
Will 2 gadi atpakaļ
vecāks
revīzija
dcf5928f3f
7 mainītis faili ar 356 papildinājumiem un 350 dzēšanām
  1. 0 1
      .clippy.toml
  2. 1 0
      CHANGELOG.md
  3. 5 3
      bench/BINARY_SIZE.md
  4. 91 89
      bench/COMPUTE_UNITS.md
  5. 91 89
      bench/STACK_MEMORY.md
  6. 10 10
      lang/src/error.rs
  7. 158 158
      tests/bench/bench.json

+ 0 - 1
.clippy.toml

@@ -1 +0,0 @@
-large-error-threshold = 1_000_000

+ 1 - 0
CHANGELOG.md

@@ -22,6 +22,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - spl: Add `TokenRecordAccount` for pNFTs ([#2597](https://github.com/coral-xyz/anchor/pull/2597)).
 - ts: Add support for unnamed(tuple) enum in accounts ([#2601](https://github.com/coral-xyz/anchor/pull/2601)).
 - cli: Add program template with multiple files for instructions, state... ([#2602](https://github.com/coral-xyz/anchor/pull/2602)).
+- lang: `Box` the inner enums of `anchor_lang::error::Error` to optimize `anchor_lang::Result` ([#2600](https://github.com/coral-xyz/anchor/pull/2600)).
 
 ### Fixes
 

+ 5 - 3
bench/BINARY_SIZE.md

@@ -16,12 +16,14 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
 
 Solana version: 1.16.0
 
-| Program | Binary Size | +/- |
-| ------- | ----------- | --- |
-| bench   | 1,153,736   | -   |
+| Program | Binary Size | +/-                    |
+| ------- | ----------- | ---------------------- |
+| bench   | 1,075,688   | 🟢 **-78,048 (6.76%)** |
 
 ### Notable changes
 
+- `Box` the `anchor_lang::Result` error variants ([#2600](https://github.com/coral-xyz/anchor/pull/2600)).
+
 ---
 
 ## [0.28.0]

+ 91 - 89
bench/COMPUTE_UNITS.md

@@ -16,98 +16,100 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
 
 Solana version: 1.16.0
 
-| Instruction                 | Compute Units | +/-               |
-| --------------------------- | ------------- | ----------------- |
-| accountInfo1                | 1,015         | -                 |
-| accountInfo2                | 1,475         | -                 |
-| accountInfo4                | 1,964         | -                 |
-| accountInfo8                | 3,841         | -                 |
-| accountEmptyInit1           | 5,817         | -                 |
-| accountEmpty1               | 1,149         | -                 |
-| accountEmptyInit2           | 10,402        | -                 |
-| accountEmpty2               | 1,754         | -                 |
-| accountEmptyInit4           | 19,508        | -                 |
-| accountEmpty4               | 2,540         | -                 |
-| accountEmptyInit8           | 37,265        | -                 |
-| accountEmpty8               | 5,016         | -                 |
-| accountSizedInit1           | 5,924         | -                 |
-| accountSized1               | 1,214         | -                 |
-| accountSizedInit2           | 10,680        | -                 |
-| accountSized2               | 1,873         | -                 |
-| accountSizedInit4           | 19,970        | -                 |
-| accountSized4               | 2,762         | -                 |
-| accountSizedInit8           | 38,122        | -                 |
-| accountSized8               | 5,353         | -                 |
-| accountUnsizedInit1         | 6,052         | -                 |
-| accountUnsized1             | 1,338         | -                 |
-| accountUnsizedInit2         | 10,929        | -                 |
-| accountUnsized2             | 1,778         | -                 |
-| accountUnsizedInit4         | 20,339        | -                 |
-| accountUnsized4             | 3,136         | -                 |
-| accountUnsizedInit8         | 39,096        | -                 |
-| accountUnsized8             | 5,952         | -                 |
-| boxedAccountEmptyInit1      | 6,034         | -                 |
-| boxedAccountEmpty1          | 888           | -                 |
-| boxedAccountEmptyInit2      | 10,633        | -                 |
-| boxedAccountEmpty2          | 1,401         | -                 |
-| boxedAccountEmptyInit4      | 19,311        | -                 |
-| boxedAccountEmpty4          | 2,424         | -                 |
-| boxedAccountEmptyInit8      | 37,136        | -                 |
-| boxedAccountEmpty8          | 4,659         | -                 |
-| boxedAccountSizedInit1      | 6,130         | -                 |
-| boxedAccountSized1          | 917           | -                 |
-| boxedAccountSizedInit2      | 10,828        | -                 |
-| boxedAccountSized2          | 1,463         | -                 |
-| boxedAccountSizedInit4      | 19,703        | -                 |
-| boxedAccountSized4          | 2,543         | -                 |
-| boxedAccountSizedInit8      | 37,919        | -                 |
-| boxedAccountSized8          | 4,898         | -                 |
-| boxedAccountUnsizedInit1    | 6,240         | -                 |
-| boxedAccountUnsized1        | 972           | -                 |
-| boxedAccountUnsizedInit2    | 11,048        | -                 |
-| boxedAccountUnsized2        | 1,570         | -                 |
-| boxedAccountUnsizedInit4    | 20,138        | -                 |
-| boxedAccountUnsized4        | 2,768         | -                 |
-| boxedAccountUnsizedInit8    | 38,791        | 🟢 **-9 (0.02%)** |
-| boxedAccountUnsized8        | 5,347         | -                 |
-| boxedInterfaceAccountMint1  | 2,296         | -                 |
-| boxedInterfaceAccountMint2  | 4,129         | -                 |
-| boxedInterfaceAccountMint4  | 7,783         | -                 |
-| boxedInterfaceAccountMint8  | 15,281        | -                 |
-| boxedInterfaceAccountToken1 | 2,023         | -                 |
-| boxedInterfaceAccountToken2 | 3,582         | -                 |
-| boxedInterfaceAccountToken4 | 6,692         | -                 |
-| boxedInterfaceAccountToken8 | 13,098        | -                 |
-| interfaceAccountMint1       | 2,364         | -                 |
-| interfaceAccountMint2       | 5,030         | -                 |
-| interfaceAccountMint4       | 9,803         | -                 |
-| interfaceAccountMint8       | 18,400        | -                 |
-| interfaceAccountToken1      | 2,091         | -                 |
-| interfaceAccountToken2      | 3,948         | -                 |
-| interfaceAccountToken4      | 7,547         | -                 |
-| interface1                  | 1,059         | -                 |
-| interface2                  | 1,479         | -                 |
-| interface4                  | 1,900         | -                 |
-| interface8                  | 3,646         | -                 |
-| program1                    | 1,053         | -                 |
-| program2                    | 1,467         | -                 |
-| program4                    | 1,878         | -                 |
-| program8                    | 3,598         | -                 |
-| signer1                     | 1,018         | -                 |
-| signer2                     | 1,484         | -                 |
-| signer4                     | 1,984         | -                 |
-| signer8                     | 3,880         | -                 |
-| systemAccount1              | 1,072         | -                 |
-| systemAccount2              | 1,590         | -                 |
-| systemAccount4              | 2,195         | -                 |
-| systemAccount8              | 4,305         | -                 |
-| uncheckedAccount1           | 1,014         | -                 |
-| uncheckedAccount2           | 1,475         | -                 |
-| uncheckedAccount4           | 1,965         | -                 |
-| uncheckedAccount8           | 3,841         | -                 |
+| Instruction                 | Compute Units | +/-                    |
+| --------------------------- | ------------- | ---------------------- |
+| accountInfo1                | 680           | 🟢 **-335 (33.00%)**   |
+| accountInfo2                | 1,083         | 🟢 **-392 (26.58%)**   |
+| accountInfo4                | 1,535         | 🟢 **-429 (21.84%)**   |
+| accountInfo8                | 2,774         | 🟢 **-1,067 (27.78%)** |
+| accountEmptyInit1           | 5,521         | 🟢 **-296 (5.09%)**    |
+| accountEmpty1               | 815           | 🟢 **-334 (29.07%)**   |
+| accountEmptyInit2           | 10,111        | 🟢 **-291 (2.80%)**    |
+| accountEmpty2               | 1,366         | 🟢 **-388 (22.12%)**   |
+| accountEmptyInit4           | 19,044        | 🟢 **-464 (2.38%)**    |
+| accountEmpty4               | 2,120         | 🟢 **-420 (16.54%)**   |
+| accountEmptyInit8           | 37,265        | -                      |
+| accountEmpty8               | 3,967         | 🟢 **-1,049 (20.91%)** |
+| accountSizedInit1           | 5,626         | 🟢 **-298 (5.03%)**    |
+| accountSized1               | 820           | 🟢 **-394 (32.45%)**   |
+| accountSizedInit2           | 10,322        | 🟢 **-358 (3.35%)**    |
+| accountSized2               | 1,411         | 🟢 **-462 (24.67%)**   |
+| accountSizedInit4           | 19,462        | 🟢 **-508 (2.54%)**    |
+| accountSized4               | 2,181         | 🟢 **-581 (21.04%)**   |
+| accountSizedInit8           | 38,122        | -                      |
+| accountSized8               | 4,104         | 🟢 **-1,249 (23.33%)** |
+| accountUnsizedInit1         | 5,742         | 🟢 **-310 (5.12%)**    |
+| accountUnsized1             | 859           | 🟢 **-479 (35.80%)**   |
+| accountUnsizedInit2         | 10,551        | 🟢 **-378 (3.46%)**    |
+| accountUnsized2             | 1,364         | 🟢 **-414 (23.28%)**   |
+| accountUnsizedInit4         | 19,927        | 🟢 **-412 (2.03%)**    |
+| accountUnsized4             | 2,341         | 🟢 **-795 (25.35%)**   |
+| accountUnsizedInit8         | 38,699        | 🟢 **-397 (1.02%)**    |
+| accountUnsized8             | 4,456         | 🟢 **-1,496 (25.13%)** |
+| boxedAccountEmptyInit1      | 5,624         | 🟢 **-410 (6.79%)**    |
+| boxedAccountEmpty1          | 888           | -                      |
+| boxedAccountEmptyInit2      | 10,221        | 🟢 **-412 (3.87%)**    |
+| boxedAccountEmpty2          | 1,401         | -                      |
+| boxedAccountEmptyInit4      | 19,030        | 🟢 **-281 (1.46%)**    |
+| boxedAccountEmpty4          | 2,424         | -                      |
+| boxedAccountEmptyInit8      | 37,136        | -                      |
+| boxedAccountEmpty8          | 4,527         | 🟢 **-132 (2.83%)**    |
+| boxedAccountSizedInit1      | 5,718         | 🟢 **-412 (6.72%)**    |
+| boxedAccountSized1          | 917           | -                      |
+| boxedAccountSizedInit2      | 10,412        | 🟢 **-416 (3.84%)**    |
+| boxedAccountSized2          | 1,463         | -                      |
+| boxedAccountSizedInit4      | 19,414        | 🟢 **-289 (1.47%)**    |
+| boxedAccountSized4          | 2,543         | -                      |
+| boxedAccountSizedInit8      | 37,919        | -                      |
+| boxedAccountSized8          | 4,766         | 🟢 **-132 (2.69%)**    |
+| boxedAccountUnsizedInit1    | 5,823         | 🟢 **-417 (6.68%)**    |
+| boxedAccountUnsized1        | 972           | -                      |
+| boxedAccountUnsizedInit2    | 10,621        | 🟢 **-427 (3.86%)**    |
+| boxedAccountUnsized2        | 1,570         | -                      |
+| boxedAccountUnsizedInit4    | 19,825        | 🟢 **-313 (1.55%)**    |
+| boxedAccountUnsized4        | 2,768         | -                      |
+| boxedAccountUnsizedInit8    | 38,791        | 🟢 **-9 (0.02%)**      |
+| boxedAccountUnsized8        | 5,207         | 🟢 **-140 (2.62%)**    |
+| boxedInterfaceAccountMint1  | 2,159         | 🟢 **-137 (5.97%)**    |
+| boxedInterfaceAccountMint2  | 3,849         | 🟢 **-280 (6.78%)**    |
+| boxedInterfaceAccountMint4  | 7,215         | 🟢 **-568 (7.30%)**    |
+| boxedInterfaceAccountMint8  | 14,044        | 🟢 **-1,237 (8.10%)**  |
+| boxedInterfaceAccountToken1 | 2,088         | 🔴 **+65 (3.21%)**     |
+| boxedInterfaceAccountToken2 | 3,706         | 🔴 **+124 (3.46%)**    |
+| boxedInterfaceAccountToken4 | 6,932         | 🔴 **+240 (3.59%)**    |
+| boxedInterfaceAccountToken8 | 13,477        | 🔴 **+379 (2.89%)**    |
+| interfaceAccountMint1       | 2,574         | 🔴 **+210 (8.88%)**    |
+| interfaceAccountMint2       | 4,410         | 🟢 **-620 (12.33%)**   |
+| interfaceAccountMint4       | 8,313         | 🟢 **-1,490 (15.20%)** |
+| interfaceAccountMint8       | 16,007        | 🟢 **-2,393 (13.01%)** |
+| interfaceAccountToken1      | 2,137         | 🔴 **+46 (2.20%)**     |
+| interfaceAccountToken2      | 4,032         | 🔴 **+84 (2.13%)**     |
+| interfaceAccountToken4      | 7,816         | 🔴 **+269 (3.56%)**    |
+| interface1                  | 726           | 🟢 **-333 (31.44%)**   |
+| interface2                  | 1,093         | 🟢 **-386 (26.10%)**   |
+| interface4                  | 1,484         | 🟢 **-416 (21.89%)**   |
+| interface8                  | 2,605         | 🟢 **-1,041 (28.55%)** |
+| program1                    | 720           | 🟢 **-333 (31.62%)**   |
+| program2                    | 1,081         | 🟢 **-386 (26.31%)**   |
+| program4                    | 1,462         | 🟢 **-416 (22.15%)**   |
+| program8                    | 2,557         | 🟢 **-1,041 (28.93%)** |
+| signer1                     | 683           | 🟢 **-335 (32.91%)**   |
+| signer2                     | 1,092         | 🟢 **-392 (26.42%)**   |
+| signer4                     | 1,555         | 🟢 **-429 (21.62%)**   |
+| signer8                     | 2,813         | 🟢 **-1,067 (27.50%)** |
+| systemAccount1              | 737           | 🟢 **-335 (31.25%)**   |
+| systemAccount2              | 1,198         | 🟢 **-392 (24.65%)**   |
+| systemAccount4              | 1,766         | 🟢 **-429 (19.54%)**   |
+| systemAccount8              | 3,238         | 🟢 **-1,067 (24.79%)** |
+| uncheckedAccount1           | 679           | 🟢 **-335 (33.04%)**   |
+| uncheckedAccount2           | 1,083         | 🟢 **-392 (26.58%)**   |
+| uncheckedAccount4           | 1,536         | 🟢 **-429 (21.83%)**   |
+| uncheckedAccount8           | 2,774         | 🟢 **-1,067 (27.78%)** |
 
 ### Notable changes
 
+- `Box` the `anchor_lang::Result` error variants ([#2600](https://github.com/coral-xyz/anchor/pull/2600)).
+
 ---
 
 ## [0.28.0]

+ 91 - 89
bench/STACK_MEMORY.md

@@ -16,98 +16,100 @@ The programs and their tests are located in [/tests/bench](https://github.com/co
 
 Solana version: 1.16.0
 
-| Instruction                    | Stack Memory | +/- |
-| ------------------------------ | ------------ | --- |
-| account_info1                  | 328          | -   |
-| account_info2                  | 376          | -   |
-| account_info4                  | 560          | -   |
-| account_info8                  | 728          | -   |
-| account_empty_init1            | 592          | -   |
-| account_empty_init2            | 560          | -   |
-| account_empty_init4            | 632          | -   |
-| account_empty_init8            | 824          | -   |
-| account_empty1                 | 320          | -   |
-| account_empty2                 | 368          | -   |
-| account_empty4                 | 552          | -   |
-| account_empty8                 | 728          | -   |
-| account_sized_init1            | 600          | -   |
-| account_sized_init2            | 552          | -   |
-| account_sized_init4            | 664          | -   |
-| account_sized_init8            | 888          | -   |
-| account_sized1                 | 328          | -   |
-| account_sized2                 | 392          | -   |
-| account_sized4                 | 568          | -   |
-| account_sized8                 | 792          | -   |
-| account_unsized_init1          | 624          | -   |
-| account_unsized_init2          | 584          | -   |
-| account_unsized_init4          | 728          | -   |
-| account_unsized_init8          | 1,016        | -   |
-| account_unsized1               | 344          | -   |
-| account_unsized2               | 456          | -   |
-| account_unsized4               | 632          | -   |
-| account_unsized8               | 920          | -   |
-| boxed_account_empty_init1      | 552          | -   |
-| boxed_account_empty_init2      | 400          | -   |
-| boxed_account_empty_init4      | 432          | -   |
-| boxed_account_empty_init8      | 496          | -   |
-| boxed_account_empty1           | 320          | -   |
-| boxed_account_empty2           | 320          | -   |
-| boxed_account_empty4           | 320          | -   |
-| boxed_account_empty8           | 336          | -   |
-| boxed_account_sized_init1      | 552          | -   |
-| boxed_account_sized_init2      | 400          | -   |
-| boxed_account_sized_init4      | 432          | -   |
-| boxed_account_sized_init8      | 496          | -   |
-| boxed_account_sized1           | 320          | -   |
-| boxed_account_sized2           | 320          | -   |
-| boxed_account_sized4           | 320          | -   |
-| boxed_account_sized8           | 336          | -   |
-| boxed_account_unsized_init1    | 552          | -   |
-| boxed_account_unsized_init2    | 400          | -   |
-| boxed_account_unsized_init4    | 432          | -   |
-| boxed_account_unsized_init8    | 496          | -   |
-| boxed_account_unsized1         | 320          | -   |
-| boxed_account_unsized2         | 320          | -   |
-| boxed_account_unsized4         | 320          | -   |
-| boxed_account_unsized8         | 336          | -   |
-| boxed_interface_account_mint1  | 320          | -   |
-| boxed_interface_account_mint2  | 320          | -   |
-| boxed_interface_account_mint4  | 320          | -   |
-| boxed_interface_account_mint8  | 336          | -   |
-| boxed_interface_account_token1 | 320          | -   |
-| boxed_interface_account_token2 | 320          | -   |
-| boxed_interface_account_token4 | 320          | -   |
-| boxed_interface_account_token8 | 336          | -   |
-| interface_account_mint1        | 504          | -   |
-| interface_account_mint2        | 680          | -   |
-| interface_account_mint4        | 1,016        | -   |
-| interface_account_mint8        | 1,688        | -   |
-| interface_account_token1       | 680          | -   |
-| interface_account_token2       | 856          | -   |
-| interface_account_token4       | 1,368        | -   |
-| interface1                     | 320          | -   |
-| interface2                     | 368          | -   |
-| interface4                     | 552          | -   |
-| interface8                     | 728          | -   |
-| program1                       | 320          | -   |
-| program2                       | 368          | -   |
-| program4                       | 552          | -   |
-| program8                       | 728          | -   |
-| signer1                        | 328          | -   |
-| signer2                        | 376          | -   |
-| signer4                        | 560          | -   |
-| signer8                        | 728          | -   |
-| system_account1                | 328          | -   |
-| system_account2                | 376          | -   |
-| system_account4                | 560          | -   |
-| system_account8                | 728          | -   |
-| unchecked_account1             | 328          | -   |
-| unchecked_account2             | 376          | -   |
-| unchecked_account4             | 560          | -   |
-| unchecked_account8             | 728          | -   |
+| Instruction                    | Stack Memory | +/-                  |
+| ------------------------------ | ------------ | -------------------- |
+| account_info1                  | 272          | 🟢 **-56 (17.07%)**  |
+| account_info2                  | 320          | 🟢 **-56 (14.89%)**  |
+| account_info4                  | 416          | 🟢 **-144 (25.71%)** |
+| account_info8                  | 608          | 🟢 **-120 (16.48%)** |
+| account_empty_init1            | 400          | 🟢 **-192 (32.43%)** |
+| account_empty_init2            | 480          | 🟢 **-80 (14.29%)**  |
+| account_empty_init4            | 528          | 🟢 **-104 (16.46%)** |
+| account_empty_init8            | 720          | 🟢 **-104 (12.62%)** |
+| account_empty1                 | 272          | 🟢 **-48 (15.00%)**  |
+| account_empty2                 | 320          | 🟢 **-48 (13.04%)**  |
+| account_empty4                 | 416          | 🟢 **-136 (24.64%)** |
+| account_empty8                 | 608          | 🟢 **-120 (16.48%)** |
+| account_sized_init1            | 408          | 🟢 **-192 (32.00%)** |
+| account_sized_init2            | 496          | 🟢 **-56 (10.14%)**  |
+| account_sized_init4            | 560          | 🟢 **-104 (15.66%)** |
+| account_sized_init8            | 784          | 🟢 **-104 (11.71%)** |
+| account_sized1                 | 280          | 🟢 **-48 (14.63%)**  |
+| account_sized2                 | 336          | 🟢 **-56 (14.29%)**  |
+| account_sized4                 | 448          | 🟢 **-120 (21.13%)** |
+| account_sized8                 | 672          | 🟢 **-120 (15.15%)** |
+| account_unsized_init1          | 424          | 🟢 **-200 (32.05%)** |
+| account_unsized_init2          | 528          | 🟢 **-56 (9.59%)**   |
+| account_unsized_init4          | 624          | 🟢 **-104 (14.29%)** |
+| account_unsized_init8          | 912          | 🟢 **-104 (10.24%)** |
+| account_unsized1               | 296          | 🟢 **-48 (13.95%)**  |
+| account_unsized2               | 368          | 🟢 **-88 (19.30%)**  |
+| account_unsized4               | 512          | 🟢 **-120 (18.99%)** |
+| account_unsized8               | 800          | 🟢 **-120 (13.04%)** |
+| boxed_account_empty_init1      | 360          | 🟢 **-192 (34.78%)** |
+| boxed_account_empty_init2      | 400          | -                    |
+| boxed_account_empty_init4      | 368          | 🟢 **-64 (14.81%)**  |
+| boxed_account_empty_init8      | 400          | 🟢 **-96 (19.35%)**  |
+| boxed_account_empty1           | 232          | 🟢 **-88 (27.50%)**  |
+| boxed_account_empty2           | 240          | 🟢 **-80 (25.00%)**  |
+| boxed_account_empty4           | 256          | 🟢 **-64 (20.00%)**  |
+| boxed_account_empty8           | 288          | 🟢 **-48 (14.29%)**  |
+| boxed_account_sized_init1      | 360          | 🟢 **-192 (34.78%)** |
+| boxed_account_sized_init2      | 400          | -                    |
+| boxed_account_sized_init4      | 368          | 🟢 **-64 (14.81%)**  |
+| boxed_account_sized_init8      | 400          | 🟢 **-96 (19.35%)**  |
+| boxed_account_sized1           | 232          | 🟢 **-88 (27.50%)**  |
+| boxed_account_sized2           | 240          | 🟢 **-80 (25.00%)**  |
+| boxed_account_sized4           | 256          | 🟢 **-64 (20.00%)**  |
+| boxed_account_sized8           | 288          | 🟢 **-48 (14.29%)**  |
+| boxed_account_unsized_init1    | 360          | 🟢 **-192 (34.78%)** |
+| boxed_account_unsized_init2    | 400          | -                    |
+| boxed_account_unsized_init4    | 368          | 🟢 **-64 (14.81%)**  |
+| boxed_account_unsized_init8    | 400          | 🟢 **-96 (19.35%)**  |
+| boxed_account_unsized1         | 232          | 🟢 **-88 (27.50%)**  |
+| boxed_account_unsized2         | 240          | 🟢 **-80 (25.00%)**  |
+| boxed_account_unsized4         | 256          | 🟢 **-64 (20.00%)**  |
+| boxed_account_unsized8         | 288          | 🟢 **-48 (14.29%)**  |
+| boxed_interface_account_mint1  | 232          | 🟢 **-88 (27.50%)**  |
+| boxed_interface_account_mint2  | 240          | 🟢 **-80 (25.00%)**  |
+| boxed_interface_account_mint4  | 256          | 🟢 **-64 (20.00%)**  |
+| boxed_interface_account_mint8  | 288          | 🟢 **-48 (14.29%)**  |
+| boxed_interface_account_token1 | 232          | 🟢 **-88 (27.50%)**  |
+| boxed_interface_account_token2 | 240          | 🟢 **-80 (25.00%)**  |
+| boxed_interface_account_token4 | 256          | 🟢 **-64 (20.00%)**  |
+| boxed_interface_account_token8 | 288          | 🟢 **-48 (14.29%)**  |
+| interface_account_mint1        | 392          | 🟢 **-112 (22.22%)** |
+| interface_account_mint2        | 560          | 🟢 **-120 (17.65%)** |
+| interface_account_mint4        | 896          | 🟢 **-120 (11.81%)** |
+| interface_account_mint8        | 1,568        | 🟢 **-120 (7.11%)**  |
+| interface_account_token1       | 480          | 🟢 **-200 (29.41%)** |
+| interface_account_token2       | 736          | 🟢 **-120 (14.02%)** |
+| interface_account_token4       | 1,248        | 🟢 **-120 (8.77%)**  |
+| interface1                     | 272          | 🟢 **-48 (15.00%)**  |
+| interface2                     | 320          | 🟢 **-48 (13.04%)**  |
+| interface4                     | 416          | 🟢 **-136 (24.64%)** |
+| interface8                     | 608          | 🟢 **-120 (16.48%)** |
+| program1                       | 272          | 🟢 **-48 (15.00%)**  |
+| program2                       | 320          | 🟢 **-48 (13.04%)**  |
+| program4                       | 416          | 🟢 **-136 (24.64%)** |
+| program8                       | 608          | 🟢 **-120 (16.48%)** |
+| signer1                        | 272          | 🟢 **-56 (17.07%)**  |
+| signer2                        | 320          | 🟢 **-56 (14.89%)**  |
+| signer4                        | 416          | 🟢 **-144 (25.71%)** |
+| signer8                        | 608          | 🟢 **-120 (16.48%)** |
+| system_account1                | 272          | 🟢 **-56 (17.07%)**  |
+| system_account2                | 320          | 🟢 **-56 (14.89%)**  |
+| system_account4                | 416          | 🟢 **-144 (25.71%)** |
+| system_account8                | 608          | 🟢 **-120 (16.48%)** |
+| unchecked_account1             | 272          | 🟢 **-56 (17.07%)**  |
+| unchecked_account2             | 320          | 🟢 **-56 (14.89%)**  |
+| unchecked_account4             | 416          | 🟢 **-144 (25.71%)** |
+| unchecked_account8             | 608          | 🟢 **-120 (16.48%)** |
 
 ### Notable changes
 
+- `Box` the `anchor_lang::Result` error variants ([#2600](https://github.com/coral-xyz/anchor/pull/2600)).
+
 ---
 
 ## [0.28.0]

+ 10 - 10
lang/src/error.rs

@@ -222,8 +222,8 @@ pub enum ErrorCode {
 
 #[derive(Debug, PartialEq, Eq)]
 pub enum Error {
-    AnchorError(AnchorError),
-    ProgramError(ProgramErrorWithOrigin),
+    AnchorError(Box<AnchorError>),
+    ProgramError(Box<ProgramErrorWithOrigin>),
 }
 
 impl std::error::Error for Error {}
@@ -239,24 +239,24 @@ impl Display for Error {
 
 impl From<AnchorError> for Error {
     fn from(ae: AnchorError) -> Self {
-        Self::AnchorError(ae)
+        Self::AnchorError(Box::new(ae))
     }
 }
 
 impl From<ProgramError> for Error {
     fn from(program_error: ProgramError) -> Self {
-        Self::ProgramError(program_error.into())
+        Self::ProgramError(Box::new(program_error.into()))
     }
 }
 impl From<BorshIoError> for Error {
     fn from(error: BorshIoError) -> Self {
-        Error::ProgramError(ProgramError::from(error).into())
+        Error::ProgramError(Box::new(ProgramError::from(error).into()))
     }
 }
 
 impl From<ProgramErrorWithOrigin> for Error {
     fn from(pe: ProgramErrorWithOrigin) -> Self {
-        Self::ProgramError(pe)
+        Self::ProgramError(Box::new(pe))
     }
 }
 
@@ -503,10 +503,10 @@ impl Eq for AnchorError {}
 impl std::convert::From<Error> for anchor_lang::solana_program::program_error::ProgramError {
     fn from(e: Error) -> anchor_lang::solana_program::program_error::ProgramError {
         match e {
-            Error::AnchorError(AnchorError {
-                error_code_number, ..
-            }) => {
-                anchor_lang::solana_program::program_error::ProgramError::Custom(error_code_number)
+            Error::AnchorError(error) => {
+                anchor_lang::solana_program::program_error::ProgramError::Custom(
+                    error.error_code_number,
+                )
             }
             Error::ProgramError(program_error) => program_error.program_error,
         }

+ 158 - 158
tests/bench/bench.json

@@ -375,185 +375,185 @@
     "solanaVersion": "1.16.0",
     "result": {
       "binarySize": {
-        "bench": 1153736
+        "bench": 1075688
       },
       "computeUnits": {
-        "accountInfo1": 1015,
-        "accountInfo2": 1475,
-        "accountInfo4": 1964,
-        "accountInfo8": 3841,
-        "accountEmptyInit1": 5817,
-        "accountEmpty1": 1149,
-        "accountEmptyInit2": 10402,
-        "accountEmpty2": 1754,
-        "accountEmptyInit4": 19508,
-        "accountEmpty4": 2540,
+        "accountInfo1": 680,
+        "accountInfo2": 1083,
+        "accountInfo4": 1535,
+        "accountInfo8": 2774,
+        "accountEmptyInit1": 5521,
+        "accountEmpty1": 815,
+        "accountEmptyInit2": 10111,
+        "accountEmpty2": 1366,
+        "accountEmptyInit4": 19044,
+        "accountEmpty4": 2120,
         "accountEmptyInit8": 37265,
-        "accountEmpty8": 5016,
-        "accountSizedInit1": 5924,
-        "accountSized1": 1214,
-        "accountSizedInit2": 10680,
-        "accountSized2": 1873,
-        "accountSizedInit4": 19970,
-        "accountSized4": 2762,
+        "accountEmpty8": 3967,
+        "accountSizedInit1": 5626,
+        "accountSized1": 820,
+        "accountSizedInit2": 10322,
+        "accountSized2": 1411,
+        "accountSizedInit4": 19462,
+        "accountSized4": 2181,
         "accountSizedInit8": 38122,
-        "accountSized8": 5353,
-        "accountUnsizedInit1": 6052,
-        "accountUnsized1": 1338,
-        "accountUnsizedInit2": 10929,
-        "accountUnsized2": 1778,
-        "accountUnsizedInit4": 20339,
-        "accountUnsized4": 3136,
-        "accountUnsizedInit8": 39096,
-        "accountUnsized8": 5952,
-        "boxedAccountEmptyInit1": 6034,
+        "accountSized8": 4104,
+        "accountUnsizedInit1": 5742,
+        "accountUnsized1": 859,
+        "accountUnsizedInit2": 10551,
+        "accountUnsized2": 1364,
+        "accountUnsizedInit4": 19927,
+        "accountUnsized4": 2341,
+        "accountUnsizedInit8": 38699,
+        "accountUnsized8": 4456,
+        "boxedAccountEmptyInit1": 5624,
         "boxedAccountEmpty1": 888,
-        "boxedAccountEmptyInit2": 10633,
+        "boxedAccountEmptyInit2": 10221,
         "boxedAccountEmpty2": 1401,
-        "boxedAccountEmptyInit4": 19311,
+        "boxedAccountEmptyInit4": 19030,
         "boxedAccountEmpty4": 2424,
         "boxedAccountEmptyInit8": 37136,
-        "boxedAccountEmpty8": 4659,
-        "boxedAccountSizedInit1": 6130,
+        "boxedAccountEmpty8": 4527,
+        "boxedAccountSizedInit1": 5718,
         "boxedAccountSized1": 917,
-        "boxedAccountSizedInit2": 10828,
+        "boxedAccountSizedInit2": 10412,
         "boxedAccountSized2": 1463,
-        "boxedAccountSizedInit4": 19703,
+        "boxedAccountSizedInit4": 19414,
         "boxedAccountSized4": 2543,
         "boxedAccountSizedInit8": 37919,
-        "boxedAccountSized8": 4898,
-        "boxedAccountUnsizedInit1": 6240,
+        "boxedAccountSized8": 4766,
+        "boxedAccountUnsizedInit1": 5823,
         "boxedAccountUnsized1": 972,
-        "boxedAccountUnsizedInit2": 11048,
+        "boxedAccountUnsizedInit2": 10621,
         "boxedAccountUnsized2": 1570,
-        "boxedAccountUnsizedInit4": 20138,
+        "boxedAccountUnsizedInit4": 19825,
         "boxedAccountUnsized4": 2768,
         "boxedAccountUnsizedInit8": 38791,
-        "boxedAccountUnsized8": 5347,
-        "boxedInterfaceAccountMint1": 2296,
-        "boxedInterfaceAccountMint2": 4129,
-        "boxedInterfaceAccountMint4": 7783,
-        "boxedInterfaceAccountMint8": 15281,
-        "boxedInterfaceAccountToken1": 2023,
-        "boxedInterfaceAccountToken2": 3582,
-        "boxedInterfaceAccountToken4": 6692,
-        "boxedInterfaceAccountToken8": 13098,
-        "interfaceAccountMint1": 2364,
-        "interfaceAccountMint2": 5030,
-        "interfaceAccountMint4": 9803,
-        "interfaceAccountMint8": 18400,
-        "interfaceAccountToken1": 2091,
-        "interfaceAccountToken2": 3948,
-        "interfaceAccountToken4": 7547,
-        "interface1": 1059,
-        "interface2": 1479,
-        "interface4": 1900,
-        "interface8": 3646,
-        "program1": 1053,
-        "program2": 1467,
-        "program4": 1878,
-        "program8": 3598,
-        "signer1": 1018,
-        "signer2": 1484,
-        "signer4": 1984,
-        "signer8": 3880,
-        "systemAccount1": 1072,
-        "systemAccount2": 1590,
-        "systemAccount4": 2195,
-        "systemAccount8": 4305,
-        "uncheckedAccount1": 1014,
-        "uncheckedAccount2": 1475,
-        "uncheckedAccount4": 1965,
-        "uncheckedAccount8": 3841
+        "boxedAccountUnsized8": 5207,
+        "boxedInterfaceAccountMint1": 2159,
+        "boxedInterfaceAccountMint2": 3849,
+        "boxedInterfaceAccountMint4": 7215,
+        "boxedInterfaceAccountMint8": 14044,
+        "boxedInterfaceAccountToken1": 2088,
+        "boxedInterfaceAccountToken2": 3706,
+        "boxedInterfaceAccountToken4": 6932,
+        "boxedInterfaceAccountToken8": 13477,
+        "interfaceAccountMint1": 2574,
+        "interfaceAccountMint2": 4410,
+        "interfaceAccountMint4": 8313,
+        "interfaceAccountMint8": 16007,
+        "interfaceAccountToken1": 2137,
+        "interfaceAccountToken2": 4032,
+        "interfaceAccountToken4": 7816,
+        "interface1": 726,
+        "interface2": 1093,
+        "interface4": 1484,
+        "interface8": 2605,
+        "program1": 720,
+        "program2": 1081,
+        "program4": 1462,
+        "program8": 2557,
+        "signer1": 683,
+        "signer2": 1092,
+        "signer4": 1555,
+        "signer8": 2813,
+        "systemAccount1": 737,
+        "systemAccount2": 1198,
+        "systemAccount4": 1766,
+        "systemAccount8": 3238,
+        "uncheckedAccount1": 679,
+        "uncheckedAccount2": 1083,
+        "uncheckedAccount4": 1536,
+        "uncheckedAccount8": 2774
       },
       "stackMemory": {
-        "account_info1": 328,
-        "account_info2": 376,
-        "account_info4": 560,
-        "account_info8": 728,
-        "account_empty_init1": 592,
-        "account_empty_init2": 560,
-        "account_empty_init4": 632,
-        "account_empty_init8": 824,
-        "account_empty1": 320,
-        "account_empty2": 368,
-        "account_empty4": 552,
-        "account_empty8": 728,
-        "account_sized_init1": 600,
-        "account_sized_init2": 552,
-        "account_sized_init4": 664,
-        "account_sized_init8": 888,
-        "account_sized1": 328,
-        "account_sized2": 392,
-        "account_sized4": 568,
-        "account_sized8": 792,
-        "account_unsized_init1": 624,
-        "account_unsized_init2": 584,
-        "account_unsized_init4": 728,
-        "account_unsized_init8": 1016,
-        "account_unsized1": 344,
-        "account_unsized2": 456,
-        "account_unsized4": 632,
-        "account_unsized8": 920,
-        "boxed_account_empty_init1": 552,
+        "account_info1": 272,
+        "account_info2": 320,
+        "account_info4": 416,
+        "account_info8": 608,
+        "account_empty_init1": 400,
+        "account_empty_init2": 480,
+        "account_empty_init4": 528,
+        "account_empty_init8": 720,
+        "account_empty1": 272,
+        "account_empty2": 320,
+        "account_empty4": 416,
+        "account_empty8": 608,
+        "account_sized_init1": 408,
+        "account_sized_init2": 496,
+        "account_sized_init4": 560,
+        "account_sized_init8": 784,
+        "account_sized1": 280,
+        "account_sized2": 336,
+        "account_sized4": 448,
+        "account_sized8": 672,
+        "account_unsized_init1": 424,
+        "account_unsized_init2": 528,
+        "account_unsized_init4": 624,
+        "account_unsized_init8": 912,
+        "account_unsized1": 296,
+        "account_unsized2": 368,
+        "account_unsized4": 512,
+        "account_unsized8": 800,
+        "boxed_account_empty_init1": 360,
         "boxed_account_empty_init2": 400,
-        "boxed_account_empty_init4": 432,
-        "boxed_account_empty_init8": 496,
-        "boxed_account_empty1": 320,
-        "boxed_account_empty2": 320,
-        "boxed_account_empty4": 320,
-        "boxed_account_empty8": 336,
-        "boxed_account_sized_init1": 552,
+        "boxed_account_empty_init4": 368,
+        "boxed_account_empty_init8": 400,
+        "boxed_account_empty1": 232,
+        "boxed_account_empty2": 240,
+        "boxed_account_empty4": 256,
+        "boxed_account_empty8": 288,
+        "boxed_account_sized_init1": 360,
         "boxed_account_sized_init2": 400,
-        "boxed_account_sized_init4": 432,
-        "boxed_account_sized_init8": 496,
-        "boxed_account_sized1": 320,
-        "boxed_account_sized2": 320,
-        "boxed_account_sized4": 320,
-        "boxed_account_sized8": 336,
-        "boxed_account_unsized_init1": 552,
+        "boxed_account_sized_init4": 368,
+        "boxed_account_sized_init8": 400,
+        "boxed_account_sized1": 232,
+        "boxed_account_sized2": 240,
+        "boxed_account_sized4": 256,
+        "boxed_account_sized8": 288,
+        "boxed_account_unsized_init1": 360,
         "boxed_account_unsized_init2": 400,
-        "boxed_account_unsized_init4": 432,
-        "boxed_account_unsized_init8": 496,
-        "boxed_account_unsized1": 320,
-        "boxed_account_unsized2": 320,
-        "boxed_account_unsized4": 320,
-        "boxed_account_unsized8": 336,
-        "boxed_interface_account_mint1": 320,
-        "boxed_interface_account_mint2": 320,
-        "boxed_interface_account_mint4": 320,
-        "boxed_interface_account_mint8": 336,
-        "boxed_interface_account_token1": 320,
-        "boxed_interface_account_token2": 320,
-        "boxed_interface_account_token4": 320,
-        "boxed_interface_account_token8": 336,
-        "interface_account_mint1": 504,
-        "interface_account_mint2": 680,
-        "interface_account_mint4": 1016,
-        "interface_account_mint8": 1688,
-        "interface_account_token1": 680,
-        "interface_account_token2": 856,
-        "interface_account_token4": 1368,
-        "interface1": 320,
-        "interface2": 368,
-        "interface4": 552,
-        "interface8": 728,
-        "program1": 320,
-        "program2": 368,
-        "program4": 552,
-        "program8": 728,
-        "signer1": 328,
-        "signer2": 376,
-        "signer4": 560,
-        "signer8": 728,
-        "system_account1": 328,
-        "system_account2": 376,
-        "system_account4": 560,
-        "system_account8": 728,
-        "unchecked_account1": 328,
-        "unchecked_account2": 376,
-        "unchecked_account4": 560,
-        "unchecked_account8": 728
+        "boxed_account_unsized_init4": 368,
+        "boxed_account_unsized_init8": 400,
+        "boxed_account_unsized1": 232,
+        "boxed_account_unsized2": 240,
+        "boxed_account_unsized4": 256,
+        "boxed_account_unsized8": 288,
+        "boxed_interface_account_mint1": 232,
+        "boxed_interface_account_mint2": 240,
+        "boxed_interface_account_mint4": 256,
+        "boxed_interface_account_mint8": 288,
+        "boxed_interface_account_token1": 232,
+        "boxed_interface_account_token2": 240,
+        "boxed_interface_account_token4": 256,
+        "boxed_interface_account_token8": 288,
+        "interface_account_mint1": 392,
+        "interface_account_mint2": 560,
+        "interface_account_mint4": 896,
+        "interface_account_mint8": 1568,
+        "interface_account_token1": 480,
+        "interface_account_token2": 736,
+        "interface_account_token4": 1248,
+        "interface1": 272,
+        "interface2": 320,
+        "interface4": 416,
+        "interface8": 608,
+        "program1": 272,
+        "program2": 320,
+        "program4": 416,
+        "program8": 608,
+        "signer1": 272,
+        "signer2": 320,
+        "signer4": 416,
+        "signer8": 608,
+        "system_account1": 272,
+        "system_account2": 320,
+        "system_account4": 416,
+        "system_account8": 608,
+        "unchecked_account1": 272,
+        "unchecked_account2": 320,
+        "unchecked_account4": 416,
+        "unchecked_account8": 608
       }
     }
   }