bench: Add benchmarking for program binary size (#2591)

This commit is contained in:
acheron 2023-08-08 22:03:31 +02:00 committed by GitHub
parent abfdc4e88f
commit 4cf447a1c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 531 additions and 445 deletions

49
bench/BINARY_SIZE.md Normal file
View File

@ -0,0 +1,49 @@
# Binary Size
All notable changes in program binary size will be documented in this file.
The changes are calculated by comparing the current results with the last version's results. Increase in size is shown with 🔴 and decrease is shown with 🟢.
The programs and their tests are located in [/tests/bench](https://github.com/coral-xyz/anchor/tree/master/tests/bench).
> **Note**
> Results documented in this file are autogenerated. Running the tests will update the current results when necessary, manually editing the results should be avoided.
> **Warning**
> Results may vary depending on Solana version.
## [Unreleased]
Solana version: 1.16.0
| Program | Binary Size | +/- |
| ------- | ----------- | --- |
| bench | 1,153,736 | - |
### Notable changes
---
## [0.28.0]
Solana version: 1.16.0
| Program | Binary Size | +/- |
| ------- | ----------- | ---------------------- |
| bench | 1,153,736 | 🔴 **+35,000 (3.13%)** |
### Notable changes
- Upgrading Solana to `1.16`. The difference in binary size between `0.27.0` and `0.28.0` is the direct result of upgrading Solana version(both build tools and crates) ([#2512](https://github.com/coral-xyz/anchor/pull/2512)).
---
## [0.27.0]
Solana version: 1.14.16
| Program | Binary Size | +/- |
| ------- | ----------- | --- |
| bench | 1,118,736 | N/A |
---

View File

@ -7,104 +7,104 @@ The changes are calculated by comparing the current results with the last versio
The programs and their tests are located in [/tests/bench](https://github.com/coral-xyz/anchor/tree/master/tests/bench). The programs and their tests are located in [/tests/bench](https://github.com/coral-xyz/anchor/tree/master/tests/bench).
> **Note** > **Note**
> The results documented in this file are autogenerated. Running the tests will update the current results when necessary, manually editing the results should be avoided. > Results documented in this file are autogenerated. Running the tests will update the current results when necessary, manually editing the results should be avoided.
> **Warning** > **Warning**
> The results may vary depending on Solana version. > Results may vary depending on Solana version.
## [Unreleased] ## [Unreleased]
Solana version: 1.16.0 Solana version: 1.16.0
| Instruction | Compute Units | +/- | | Instruction | Compute Units | +/- |
| --------------------------- | ------------- | --- | | --------------------------- | ------------- | ----------------- |
| accountInfo1 | 1015 | - | | accountInfo1 | 1,015 | - |
| accountInfo2 | 1475 | - | | accountInfo2 | 1,475 | - |
| accountInfo4 | 1964 | - | | accountInfo4 | 1,964 | - |
| accountInfo8 | 3841 | - | | accountInfo8 | 3,841 | - |
| accountEmptyInit1 | 5817 | - | | accountEmptyInit1 | 5,817 | - |
| accountEmpty1 | 1149 | - | | accountEmpty1 | 1,149 | - |
| accountEmptyInit2 | 10402 | - | | accountEmptyInit2 | 10,402 | - |
| accountEmpty2 | 1754 | - | | accountEmpty2 | 1,754 | - |
| accountEmptyInit4 | 19508 | - | | accountEmptyInit4 | 19,508 | - |
| accountEmpty4 | 2540 | - | | accountEmpty4 | 2,540 | - |
| accountEmptyInit8 | 37265 | - | | accountEmptyInit8 | 37,265 | - |
| accountEmpty8 | 5016 | - | | accountEmpty8 | 5,016 | - |
| accountSizedInit1 | 5924 | - | | accountSizedInit1 | 5,924 | - |
| accountSized1 | 1214 | - | | accountSized1 | 1,214 | - |
| accountSizedInit2 | 10680 | - | | accountSizedInit2 | 10,680 | - |
| accountSized2 | 1873 | - | | accountSized2 | 1,873 | - |
| accountSizedInit4 | 19970 | - | | accountSizedInit4 | 19,970 | - |
| accountSized4 | 2762 | - | | accountSized4 | 2,762 | - |
| accountSizedInit8 | 38122 | - | | accountSizedInit8 | 38,122 | - |
| accountSized8 | 5353 | - | | accountSized8 | 5,353 | - |
| accountUnsizedInit1 | 6052 | - | | accountUnsizedInit1 | 6,052 | - |
| accountUnsized1 | 1338 | - | | accountUnsized1 | 1,338 | - |
| accountUnsizedInit2 | 10929 | - | | accountUnsizedInit2 | 10,929 | - |
| accountUnsized2 | 1778 | - | | accountUnsized2 | 1,778 | - |
| accountUnsizedInit4 | 20339 | - | | accountUnsizedInit4 | 20,339 | - |
| accountUnsized4 | 3136 | - | | accountUnsized4 | 3,136 | - |
| accountUnsizedInit8 | 39096 | - | | accountUnsizedInit8 | 39,096 | - |
| accountUnsized8 | 5952 | - | | accountUnsized8 | 5,952 | - |
| boxedAccountEmptyInit1 | 6034 | - | | boxedAccountEmptyInit1 | 6,034 | - |
| boxedAccountEmpty1 | 888 | - | | boxedAccountEmpty1 | 888 | - |
| boxedAccountEmptyInit2 | 10633 | - | | boxedAccountEmptyInit2 | 10,633 | - |
| boxedAccountEmpty2 | 1401 | - | | boxedAccountEmpty2 | 1,401 | - |
| boxedAccountEmptyInit4 | 19311 | - | | boxedAccountEmptyInit4 | 19,311 | - |
| boxedAccountEmpty4 | 2424 | - | | boxedAccountEmpty4 | 2,424 | - |
| boxedAccountEmptyInit8 | 37136 | - | | boxedAccountEmptyInit8 | 37,136 | - |
| boxedAccountEmpty8 | 4659 | - | | boxedAccountEmpty8 | 4,659 | - |
| boxedAccountSizedInit1 | 6130 | - | | boxedAccountSizedInit1 | 6,130 | - |
| boxedAccountSized1 | 917 | - | | boxedAccountSized1 | 917 | - |
| boxedAccountSizedInit2 | 10828 | - | | boxedAccountSizedInit2 | 10,828 | - |
| boxedAccountSized2 | 1463 | - | | boxedAccountSized2 | 1,463 | - |
| boxedAccountSizedInit4 | 19703 | - | | boxedAccountSizedInit4 | 19,703 | - |
| boxedAccountSized4 | 2543 | - | | boxedAccountSized4 | 2,543 | - |
| boxedAccountSizedInit8 | 37919 | - | | boxedAccountSizedInit8 | 37,919 | - |
| boxedAccountSized8 | 4898 | - | | boxedAccountSized8 | 4,898 | - |
| boxedAccountUnsizedInit1 | 6240 | - | | boxedAccountUnsizedInit1 | 6,240 | - |
| boxedAccountUnsized1 | 972 | - | | boxedAccountUnsized1 | 972 | - |
| boxedAccountUnsizedInit2 | 11048 | - | | boxedAccountUnsizedInit2 | 11,048 | - |
| boxedAccountUnsized2 | 1570 | - | | boxedAccountUnsized2 | 1,570 | - |
| boxedAccountUnsizedInit4 | 20138 | - | | boxedAccountUnsizedInit4 | 20,138 | - |
| boxedAccountUnsized4 | 2768 | - | | boxedAccountUnsized4 | 2,768 | - |
| boxedAccountUnsizedInit8 | 38791 | - | | boxedAccountUnsizedInit8 | 38,791 | 🟢 **-9 (0.02%)** |
| boxedAccountUnsized8 | 5347 | - | | boxedAccountUnsized8 | 5,347 | - |
| boxedInterfaceAccountMint1 | 2296 | - | | boxedInterfaceAccountMint1 | 2,296 | - |
| boxedInterfaceAccountMint2 | 4129 | - | | boxedInterfaceAccountMint2 | 4,129 | - |
| boxedInterfaceAccountMint4 | 7783 | - | | boxedInterfaceAccountMint4 | 7,783 | - |
| boxedInterfaceAccountMint8 | 15281 | - | | boxedInterfaceAccountMint8 | 15,281 | - |
| boxedInterfaceAccountToken1 | 2023 | - | | boxedInterfaceAccountToken1 | 2,023 | - |
| boxedInterfaceAccountToken2 | 3582 | - | | boxedInterfaceAccountToken2 | 3,582 | - |
| boxedInterfaceAccountToken4 | 6692 | - | | boxedInterfaceAccountToken4 | 6,692 | - |
| boxedInterfaceAccountToken8 | 13098 | - | | boxedInterfaceAccountToken8 | 13,098 | - |
| interfaceAccountMint1 | 2364 | - | | interfaceAccountMint1 | 2,364 | - |
| interfaceAccountMint2 | 5030 | - | | interfaceAccountMint2 | 5,030 | - |
| interfaceAccountMint4 | 9803 | - | | interfaceAccountMint4 | 9,803 | - |
| interfaceAccountMint8 | 18400 | - | | interfaceAccountMint8 | 18,400 | - |
| interfaceAccountToken1 | 2091 | - | | interfaceAccountToken1 | 2,091 | - |
| interfaceAccountToken2 | 3948 | - | | interfaceAccountToken2 | 3,948 | - |
| interfaceAccountToken4 | 7547 | - | | interfaceAccountToken4 | 7,547 | - |
| interface1 | 1059 | - | | interface1 | 1,059 | - |
| interface2 | 1479 | - | | interface2 | 1,479 | - |
| interface4 | 1900 | - | | interface4 | 1,900 | - |
| interface8 | 3646 | - | | interface8 | 3,646 | - |
| program1 | 1053 | - | | program1 | 1,053 | - |
| program2 | 1467 | - | | program2 | 1,467 | - |
| program4 | 1878 | - | | program4 | 1,878 | - |
| program8 | 3598 | - | | program8 | 3,598 | - |
| signer1 | 1018 | - | | signer1 | 1,018 | - |
| signer2 | 1484 | - | | signer2 | 1,484 | - |
| signer4 | 1984 | - | | signer4 | 1,984 | - |
| signer8 | 3880 | - | | signer8 | 3,880 | - |
| systemAccount1 | 1072 | - | | systemAccount1 | 1,072 | - |
| systemAccount2 | 1590 | - | | systemAccount2 | 1,590 | - |
| systemAccount4 | 2195 | - | | systemAccount4 | 2,195 | - |
| systemAccount8 | 4305 | - | | systemAccount8 | 4,305 | - |
| uncheckedAccount1 | 1014 | - | | uncheckedAccount1 | 1,014 | - |
| uncheckedAccount2 | 1475 | - | | uncheckedAccount2 | 1,475 | - |
| uncheckedAccount4 | 1965 | - | | uncheckedAccount4 | 1,965 | - |
| uncheckedAccount8 | 3841 | - | | uncheckedAccount8 | 3,841 | - |
### Notable changes ### Notable changes
@ -114,95 +114,95 @@ Solana version: 1.16.0
Solana version: 1.16.0 Solana version: 1.16.0
| Instruction | Compute Units | +/- | | Instruction | Compute Units | +/- |
| --------------------------- | ------------- | --------------------- | | --------------------------- | ------------- | ---------------------- |
| accountInfo1 | 1015 | 🔴 **+61 (6.39%)** | | accountInfo1 | 1,015 | 🔴 **+61 (6.39%)** |
| accountInfo2 | 1475 | 🟢 **-92 (5.87%)** | | accountInfo2 | 1,475 | 🟢 **-92 (5.87%)** |
| accountInfo4 | 1964 | 🟢 **-95 (4.61%)** | | accountInfo4 | 1,964 | 🟢 **-95 (4.61%)** |
| accountInfo8 | 3841 | - | | accountInfo8 | 3,841 | 🟢 **-15 (0.39%)** |
| accountEmptyInit1 | 5817 | 🟢 **-141 (2.37%)** | | accountEmptyInit1 | 5,817 | 🟢 **-141 (2.37%)** |
| accountEmpty1 | 1149 | 🔴 **+59 (5.41%)** | | accountEmpty1 | 1,149 | 🔴 **+59 (5.41%)** |
| accountEmptyInit2 | 10402 | 🟢 **-172 (1.63%)** | | accountEmptyInit2 | 10,402 | 🟢 **-172 (1.63%)** |
| accountEmpty2 | 1754 | 🟢 **-98 (5.29%)** | | accountEmpty2 | 1,754 | 🟢 **-98 (5.29%)** |
| accountEmptyInit4 | 19508 | - | | accountEmptyInit4 | 19,508 | 🟢 **-49 (0.25%)** |
| accountEmpty4 | 2540 | 🟢 **-106 (4.01%)** | | accountEmpty4 | 2,540 | 🟢 **-106 (4.01%)** |
| accountEmptyInit8 | 37265 | - | | accountEmptyInit8 | 37,265 | 🟢 **-276 (0.74%)** |
| accountEmpty8 | 5016 | - | | accountEmpty8 | 5,016 | 🟢 **-27 (0.54%)** |
| accountSizedInit1 | 5924 | 🟢 **-139 (2.29%)** | | accountSizedInit1 | 5,924 | 🟢 **-139 (2.29%)** |
| accountSized1 | 1214 | 🔴 **+79 (6.96%)** | | accountSized1 | 1,214 | 🔴 **+79 (6.96%)** |
| accountSizedInit2 | 10680 | - | | accountSizedInit2 | 10,680 | 🟢 **-103 (0.96%)** |
| accountSized2 | 1873 | 🟢 **-93 (4.73%)** | | accountSized2 | 1,873 | 🟢 **-93 (4.73%)** |
| accountSizedInit4 | 19970 | - | | accountSizedInit4 | 19,970 | 🟢 **-5 (0.03%)** |
| accountSized4 | 2762 | - | | accountSized4 | 2,762 | 🟢 **-25 (0.90%)** |
| accountSizedInit8 | 38122 | - | | accountSizedInit8 | 38,122 | 🟢 **-259 (0.67%)** |
| accountSized8 | 5353 | - | | accountSized8 | 5,353 | 🟢 **-6 (0.11%)** |
| accountUnsizedInit1 | 6052 | 🟢 **-141 (2.28%)** | | accountUnsizedInit1 | 6,052 | 🟢 **-141 (2.28%)** |
| accountUnsized1 | 1338 | 🔴 **+95 (7.64%)** | | accountUnsized1 | 1,338 | 🔴 **+95 (7.64%)** |
| accountUnsizedInit2 | 10929 | 🟢 **-113 (1.02%)** | | accountUnsizedInit2 | 10,929 | 🟢 **-113 (1.02%)** |
| accountUnsized2 | 1778 | 🟢 **-115 (6.08%)** | | accountUnsized2 | 1,778 | 🟢 **-115 (6.08%)** |
| accountUnsizedInit4 | 20339 | - | | accountUnsizedInit4 | 20,339 | 🟢 **-156 (0.76%)** |
| accountUnsized4 | 3136 | 🔴 **+32 (1.03%)** | | accountUnsized4 | 3,136 | 🔴 **+32 (1.03%)** |
| accountUnsizedInit8 | 39096 | - | | accountUnsizedInit8 | 39,096 | 🟢 **-323 (0.82%)** |
| accountUnsized8 | 5952 | 🟢 **-99 (1.64%)** | | accountUnsized8 | 5,952 | 🟢 **-99 (1.64%)** |
| boxedAccountEmptyInit1 | 6034 | 🟢 **-126 (2.05%)** | | boxedAccountEmptyInit1 | 6,034 | 🟢 **-126 (2.05%)** |
| boxedAccountEmpty1 | 888 | 🟢 **-88 (9.02%)** | | boxedAccountEmpty1 | 888 | 🟢 **-88 (9.02%)** |
| boxedAccountEmptyInit2 | 10633 | 🟢 **-151 (1.40%)** | | boxedAccountEmptyInit2 | 10,633 | 🟢 **-151 (1.40%)** |
| boxedAccountEmpty2 | 1401 | 🟢 **-98 (6.54%)** | | boxedAccountEmpty2 | 1,401 | 🟢 **-98 (6.54%)** |
| boxedAccountEmptyInit4 | 19311 | - | | boxedAccountEmptyInit4 | 19,311 | 🟢 **-189 (0.97%)** |
| boxedAccountEmpty4 | 2424 | 🟢 **-106 (4.19%)** | | boxedAccountEmpty4 | 2,424 | 🟢 **-106 (4.19%)** |
| boxedAccountEmptyInit8 | 37136 | - | | boxedAccountEmptyInit8 | 37,136 | 🟢 **-279 (0.75%)** |
| boxedAccountEmpty8 | 4659 | 🟢 **-121 (2.53%)** | | boxedAccountEmpty8 | 4,659 | 🟢 **-121 (2.53%)** |
| boxedAccountSizedInit1 | 6130 | 🟢 **-126 (2.01%)** | | boxedAccountSizedInit1 | 6,130 | 🟢 **-126 (2.01%)** |
| boxedAccountSized1 | 917 | 🟢 **-86 (8.57%)** | | boxedAccountSized1 | 917 | 🟢 **-86 (8.57%)** |
| boxedAccountSizedInit2 | 10828 | 🟢 **-147 (1.34%)** | | boxedAccountSizedInit2 | 10,828 | 🟢 **-147 (1.34%)** |
| boxedAccountSized2 | 1463 | 🟢 **-91 (5.86%)** | | boxedAccountSized2 | 1,463 | 🟢 **-91 (5.86%)** |
| boxedAccountSizedInit4 | 19703 | - | | boxedAccountSizedInit4 | 19,703 | 🟢 **-181 (0.91%)** |
| boxedAccountSized4 | 2543 | 🟢 **-99 (3.75%)** | | boxedAccountSized4 | 2,543 | 🟢 **-99 (3.75%)** |
| boxedAccountSizedInit8 | 37919 | - | | boxedAccountSizedInit8 | 37,919 | 🟢 **-263 (0.69%)** |
| boxedAccountSized8 | 4898 | 🟢 **-105 (2.10%)** | | boxedAccountSized8 | 4,898 | 🟢 **-105 (2.10%)** |
| boxedAccountUnsizedInit1 | 6240 | 🟢 **-134 (2.10%)** | | boxedAccountUnsizedInit1 | 6,240 | 🟢 **-134 (2.10%)** |
| boxedAccountUnsized1 | 972 | 🟢 **-97 (9.07%)** | | boxedAccountUnsized1 | 972 | 🟢 **-97 (9.07%)** |
| boxedAccountUnsizedInit2 | 11048 | 🟢 **-163 (1.45%)** | | boxedAccountUnsizedInit2 | 11,048 | 🟢 **-163 (1.45%)** |
| boxedAccountUnsized2 | 1570 | 🟢 **-109 (6.49%)** | | boxedAccountUnsized2 | 1,570 | 🟢 **-109 (6.49%)** |
| boxedAccountUnsizedInit4 | 20138 | 🟢 **-213 (1.05%)** | | boxedAccountUnsizedInit4 | 20,138 | 🟢 **-213 (1.05%)** |
| boxedAccountUnsized4 | 2768 | 🟢 **-131 (4.52%)** | | boxedAccountUnsized4 | 2,768 | 🟢 **-131 (4.52%)** |
| boxedAccountUnsizedInit8 | 38800 | - | | boxedAccountUnsizedInit8 | 38,800 | 🟢 **-318 (0.81%)** |
| boxedAccountUnsized8 | 5347 | 🟢 **-170 (3.08%)** | | boxedAccountUnsized8 | 5,347 | 🟢 **-170 (3.08%)** |
| boxedInterfaceAccountMint1 | 2296 | - | | boxedInterfaceAccountMint1 | 2,296 | 🟢 **-3 (0.13%)** |
| boxedInterfaceAccountMint2 | 4129 | 🔴 **+76 (1.88%)** | | boxedInterfaceAccountMint2 | 4,129 | 🔴 **+76 (1.88%)** |
| boxedInterfaceAccountMint4 | 7783 | 🔴 **+245 (3.25%)** | | boxedInterfaceAccountMint4 | 7,783 | 🔴 **+245 (3.25%)** |
| boxedInterfaceAccountMint8 | 15281 | 🔴 **+582 (3.96%)** | | boxedInterfaceAccountMint8 | 15,281 | 🔴 **+582 (3.96%)** |
| boxedInterfaceAccountToken1 | 2023 | 🔴 **+286 (16.47%)** | | boxedInterfaceAccountToken1 | 2,023 | 🔴 **+286 (16.47%)** |
| boxedInterfaceAccountToken2 | 3582 | 🔴 **+654 (22.34%)** | | boxedInterfaceAccountToken2 | 3,582 | 🔴 **+654 (22.34%)** |
| boxedInterfaceAccountToken4 | 6692 | 🔴 **+1401 (26.48%)** | | boxedInterfaceAccountToken4 | 6,692 | 🔴 **+1,401 (26.48%)** |
| boxedInterfaceAccountToken8 | 13098 | 🔴 **+2893 (28.35%)** | | boxedInterfaceAccountToken8 | 13,098 | 🔴 **+2,893 (28.35%)** |
| interfaceAccountMint1 | 2364 | 🟢 **-166 (6.56%)** | | interfaceAccountMint1 | 2,364 | 🟢 **-166 (6.56%)** |
| interfaceAccountMint2 | 5030 | 🔴 **+304 (6.43%)** | | interfaceAccountMint2 | 5,030 | 🔴 **+304 (6.43%)** |
| interfaceAccountMint4 | 9803 | 🔴 **+372 (3.94%)** | | interfaceAccountMint4 | 9,803 | 🔴 **+372 (3.94%)** |
| interfaceAccountMint8 | 18400 | 🔴 **+691 (3.90%)** | | interfaceAccountMint8 | 18,400 | 🔴 **+691 (3.90%)** |
| interfaceAccountToken1 | 2091 | 🔴 **+336 (19.15%)** | | interfaceAccountToken1 | 2,091 | 🔴 **+336 (19.15%)** |
| interfaceAccountToken2 | 3948 | 🔴 **+737 (22.95%)** | | interfaceAccountToken2 | 3,948 | 🔴 **+737 (22.95%)** |
| interfaceAccountToken4 | 7547 | 🔴 **+1541 (25.66%)** | | interfaceAccountToken4 | 7,547 | 🔴 **+1,541 (25.66%)** |
| interface1 | 1059 | 🔴 **+60 (6.01%)** | | interface1 | 1,059 | 🔴 **+60 (6.01%)** |
| interface2 | 1479 | 🟢 **-95 (6.04%)** | | interface2 | 1,479 | 🟢 **-95 (6.04%)** |
| interface4 | 1900 | 🟢 **-96 (4.81%)** | | interface4 | 1,900 | 🟢 **-96 (4.81%)** |
| interface8 | 3646 | - | | interface8 | 3,646 | 🟢 **-5 (0.14%)** |
| program1 | 1053 | 🔴 **+54 (5.41%)** | | program1 | 1,053 | 🔴 **+54 (5.41%)** |
| program2 | 1467 | 🟢 **-106 (6.74%)** | | program2 | 1,467 | 🟢 **-106 (6.74%)** |
| program4 | 1878 | 🟢 **-120 (6.01%)** | | program4 | 1,878 | 🟢 **-120 (6.01%)** |
| program8 | 3598 | 🟢 **-53 (1.45%)** | | program8 | 3,598 | 🟢 **-53 (1.45%)** |
| signer1 | 1018 | 🔴 **+60 (6.26%)** | | signer1 | 1,018 | 🔴 **+60 (6.26%)** |
| signer2 | 1484 | 🟢 **-92 (5.84%)** | | signer2 | 1,484 | 🟢 **-92 (5.84%)** |
| signer4 | 1984 | 🟢 **-95 (4.57%)** | | signer4 | 1,984 | 🟢 **-95 (4.57%)** |
| signer8 | 3880 | - | | signer8 | 3,880 | 🟢 **-15 (0.39%)** |
| systemAccount1 | 1072 | 🔴 **+59 (5.82%)** | | systemAccount1 | 1,072 | 🔴 **+59 (5.82%)** |
| systemAccount2 | 1590 | 🟢 **-96 (5.69%)** | | systemAccount2 | 1,590 | 🟢 **-96 (5.69%)** |
| systemAccount4 | 2195 | 🟢 **-103 (4.48%)** | | systemAccount4 | 2,195 | 🟢 **-103 (4.48%)** |
| systemAccount8 | 4305 | - | | systemAccount8 | 4,305 | 🟢 **-31 (0.71%)** |
| uncheckedAccount1 | 1014 | 🔴 **+61 (6.40%)** | | uncheckedAccount1 | 1,014 | 🔴 **+61 (6.40%)** |
| uncheckedAccount2 | 1475 | 🟢 **-92 (5.87%)** | | uncheckedAccount2 | 1,475 | 🟢 **-92 (5.87%)** |
| uncheckedAccount4 | 1965 | 🟢 **-95 (4.61%)** | | uncheckedAccount4 | 1,965 | 🟢 **-95 (4.61%)** |
| uncheckedAccount8 | 3841 | - | | uncheckedAccount8 | 3,841 | 🟢 **-14 (0.36%)** |
### Notable changes ### Notable changes
@ -217,91 +217,91 @@ Solana version: 1.14.16
| Instruction | Compute Units | +/- | | Instruction | Compute Units | +/- |
| --------------------------- | ------------- | --- | | --------------------------- | ------------- | --- |
| accountInfo1 | 954 | N/A | | accountInfo1 | 954 | N/A |
| accountInfo2 | 1567 | N/A | | accountInfo2 | 1,567 | N/A |
| accountInfo4 | 2059 | N/A | | accountInfo4 | 2,059 | N/A |
| accountInfo8 | 3856 | N/A | | accountInfo8 | 3,856 | N/A |
| accountEmptyInit1 | 5958 | N/A | | accountEmptyInit1 | 5,958 | N/A |
| accountEmpty1 | 1090 | N/A | | accountEmpty1 | 1,090 | N/A |
| accountEmptyInit2 | 10574 | N/A | | accountEmptyInit2 | 10,574 | N/A |
| accountEmpty2 | 1852 | N/A | | accountEmpty2 | 1,852 | N/A |
| accountEmptyInit4 | 19557 | N/A | | accountEmptyInit4 | 19,557 | N/A |
| accountEmpty4 | 2646 | N/A | | accountEmpty4 | 2,646 | N/A |
| accountEmptyInit8 | 37541 | N/A | | accountEmptyInit8 | 37,541 | N/A |
| accountEmpty8 | 5043 | N/A | | accountEmpty8 | 5,043 | N/A |
| accountSizedInit1 | 6063 | N/A | | accountSizedInit1 | 6,063 | N/A |
| accountSized1 | 1135 | N/A | | accountSized1 | 1,135 | N/A |
| accountSizedInit2 | 10783 | N/A | | accountSizedInit2 | 10,783 | N/A |
| accountSized2 | 1966 | N/A | | accountSized2 | 1,966 | N/A |
| accountSizedInit4 | 19975 | N/A | | accountSizedInit4 | 19,975 | N/A |
| accountSized4 | 2787 | N/A | | accountSized4 | 2,787 | N/A |
| accountSizedInit8 | 38381 | N/A | | accountSizedInit8 | 38,381 | N/A |
| accountSized8 | 5359 | N/A | | accountSized8 | 5,359 | N/A |
| accountUnsizedInit1 | 6193 | N/A | | accountUnsizedInit1 | 6,193 | N/A |
| accountUnsized1 | 1243 | N/A | | accountUnsized1 | 1,243 | N/A |
| accountUnsizedInit2 | 11042 | N/A | | accountUnsizedInit2 | 11,042 | N/A |
| accountUnsized2 | 1893 | N/A | | accountUnsized2 | 1,893 | N/A |
| accountUnsizedInit4 | 20495 | N/A | | accountUnsizedInit4 | 20,495 | N/A |
| accountUnsized4 | 3104 | N/A | | accountUnsized4 | 3,104 | N/A |
| accountUnsizedInit8 | 39419 | N/A | | accountUnsizedInit8 | 39,419 | N/A |
| accountUnsized8 | 6051 | N/A | | accountUnsized8 | 6,051 | N/A |
| boxedAccountEmptyInit1 | 6160 | N/A | | boxedAccountEmptyInit1 | 6,160 | N/A |
| boxedAccountEmpty1 | 976 | N/A | | boxedAccountEmpty1 | 976 | N/A |
| boxedAccountEmptyInit2 | 10784 | N/A | | boxedAccountEmptyInit2 | 10,784 | N/A |
| boxedAccountEmpty2 | 1499 | N/A | | boxedAccountEmpty2 | 1,499 | N/A |
| boxedAccountEmptyInit4 | 19500 | N/A | | boxedAccountEmptyInit4 | 19,500 | N/A |
| boxedAccountEmpty4 | 2530 | N/A | | boxedAccountEmpty4 | 2,530 | N/A |
| boxedAccountEmptyInit8 | 37415 | N/A | | boxedAccountEmptyInit8 | 37,415 | N/A |
| boxedAccountEmpty8 | 4780 | N/A | | boxedAccountEmpty8 | 4,780 | N/A |
| boxedAccountSizedInit1 | 6256 | N/A | | boxedAccountSizedInit1 | 6,256 | N/A |
| boxedAccountSized1 | 1003 | N/A | | boxedAccountSized1 | 1,003 | N/A |
| boxedAccountSizedInit2 | 10975 | N/A | | boxedAccountSizedInit2 | 10,975 | N/A |
| boxedAccountSized2 | 1554 | N/A | | boxedAccountSized2 | 1,554 | N/A |
| boxedAccountSizedInit4 | 19884 | N/A | | boxedAccountSizedInit4 | 19,884 | N/A |
| boxedAccountSized4 | 2642 | N/A | | boxedAccountSized4 | 2,642 | N/A |
| boxedAccountSizedInit8 | 38182 | N/A | | boxedAccountSizedInit8 | 38,182 | N/A |
| boxedAccountSized8 | 5003 | N/A | | boxedAccountSized8 | 5,003 | N/A |
| boxedAccountUnsizedInit1 | 6374 | N/A | | boxedAccountUnsizedInit1 | 6,374 | N/A |
| boxedAccountUnsized1 | 1069 | N/A | | boxedAccountUnsized1 | 1,069 | N/A |
| boxedAccountUnsizedInit2 | 11211 | N/A | | boxedAccountUnsizedInit2 | 11,211 | N/A |
| boxedAccountUnsized2 | 1679 | N/A | | boxedAccountUnsized2 | 1,679 | N/A |
| boxedAccountUnsizedInit4 | 20351 | N/A | | boxedAccountUnsizedInit4 | 20,351 | N/A |
| boxedAccountUnsized4 | 2899 | N/A | | boxedAccountUnsized4 | 2,899 | N/A |
| boxedAccountUnsizedInit8 | 39118 | N/A | | boxedAccountUnsizedInit8 | 39,118 | N/A |
| boxedAccountUnsized8 | 5517 | N/A | | boxedAccountUnsized8 | 5,517 | N/A |
| boxedInterfaceAccountMint1 | 2299 | N/A | | boxedInterfaceAccountMint1 | 2,299 | N/A |
| boxedInterfaceAccountMint2 | 4053 | N/A | | boxedInterfaceAccountMint2 | 4,053 | N/A |
| boxedInterfaceAccountMint4 | 7538 | N/A | | boxedInterfaceAccountMint4 | 7,538 | N/A |
| boxedInterfaceAccountMint8 | 14699 | N/A | | boxedInterfaceAccountMint8 | 14,699 | N/A |
| boxedInterfaceAccountToken1 | 1737 | N/A | | boxedInterfaceAccountToken1 | 1,737 | N/A |
| boxedInterfaceAccountToken2 | 2928 | N/A | | boxedInterfaceAccountToken2 | 2,928 | N/A |
| boxedInterfaceAccountToken4 | 5291 | N/A | | boxedInterfaceAccountToken4 | 5,291 | N/A |
| boxedInterfaceAccountToken8 | 10205 | N/A | | boxedInterfaceAccountToken8 | 10,205 | N/A |
| interfaceAccountMint1 | 2530 | N/A | | interfaceAccountMint1 | 2,530 | N/A |
| interfaceAccountMint2 | 4726 | N/A | | interfaceAccountMint2 | 4,726 | N/A |
| interfaceAccountMint4 | 9431 | N/A | | interfaceAccountMint4 | 9,431 | N/A |
| interfaceAccountMint8 | 17709 | N/A | | interfaceAccountMint8 | 17,709 | N/A |
| interfaceAccountToken1 | 1755 | N/A | | interfaceAccountToken1 | 1,755 | N/A |
| interfaceAccountToken2 | 3211 | N/A | | interfaceAccountToken2 | 3,211 | N/A |
| interfaceAccountToken4 | 6006 | N/A | | interfaceAccountToken4 | 6,006 | N/A |
| interface1 | 999 | N/A | | interface1 | 999 | N/A |
| interface2 | 1574 | N/A | | interface2 | 1,574 | N/A |
| interface4 | 1996 | N/A | | interface4 | 1,996 | N/A |
| interface8 | 3651 | N/A | | interface8 | 3,651 | N/A |
| program1 | 999 | N/A | | program1 | 999 | N/A |
| program2 | 1573 | N/A | | program2 | 1,573 | N/A |
| program4 | 1998 | N/A | | program4 | 1,998 | N/A |
| program8 | 3651 | N/A | | program8 | 3,651 | N/A |
| signer1 | 958 | N/A | | signer1 | 958 | N/A |
| signer2 | 1576 | N/A | | signer2 | 1,576 | N/A |
| signer4 | 2079 | N/A | | signer4 | 2,079 | N/A |
| signer8 | 3895 | N/A | | signer8 | 3,895 | N/A |
| systemAccount1 | 1013 | N/A | | systemAccount1 | 1,013 | N/A |
| systemAccount2 | 1686 | N/A | | systemAccount2 | 1,686 | N/A |
| systemAccount4 | 2298 | N/A | | systemAccount4 | 2,298 | N/A |
| systemAccount8 | 4336 | N/A | | systemAccount8 | 4,336 | N/A |
| uncheckedAccount1 | 953 | N/A | | uncheckedAccount1 | 953 | N/A |
| uncheckedAccount2 | 1567 | N/A | | uncheckedAccount2 | 1,567 | N/A |
| uncheckedAccount4 | 2060 | N/A | | uncheckedAccount4 | 2,060 | N/A |
| uncheckedAccount8 | 3855 | N/A | | uncheckedAccount8 | 3,855 | N/A |
--- ---

View File

@ -2,6 +2,9 @@
"0.27.0": { "0.27.0": {
"solanaVersion": "1.14.16", "solanaVersion": "1.14.16",
"result": { "result": {
"binarySize": {
"bench": 1118736
},
"computeUnits": { "computeUnits": {
"accountInfo1": 954, "accountInfo1": 954,
"accountInfo2": 1567, "accountInfo2": 1567,
@ -96,6 +99,9 @@
"0.28.0": { "0.28.0": {
"solanaVersion": "1.16.0", "solanaVersion": "1.16.0",
"result": { "result": {
"binarySize": {
"bench": 1153736
},
"computeUnits": { "computeUnits": {
"accountInfo1": 1015, "accountInfo1": 1015,
"accountInfo2": 1475, "accountInfo2": 1475,
@ -190,6 +196,9 @@
"unreleased": { "unreleased": {
"solanaVersion": "1.16.0", "solanaVersion": "1.16.0",
"result": { "result": {
"binarySize": {
"bench": 1153736
},
"computeUnits": { "computeUnits": {
"accountInfo1": 1015, "accountInfo1": 1015,
"accountInfo2": 1475, "accountInfo2": 1475,
@ -281,4 +290,4 @@
} }
} }
} }
} }

View File

@ -1,80 +1,69 @@
/** Sync Markdown files in /bench based on the data from bench.json */ /** Sync Markdown files in /bench based on the data from bench.json */
import { BenchData, Markdown } from "./utils"; import { BenchData, BenchResult, Markdown } from "./utils";
(async () => { (async () => {
const bench = await BenchData.open(); const bench = await BenchData.open();
await BenchData.forEachMarkdown((markdown, fileName) => { await BenchData.forEachMarkdown((markdown, fileName) => {
if (fileName === "COMPUTE_UNITS.md") { const resultType = fileName
const versions = bench.getVersions(); .toLowerCase()
.replace(".md", "")
.replace(/_\w/g, (match) => match[1].toUpperCase()) as keyof BenchResult;
// On the first version, compare with itself to update it with no changes const versions = bench.getVersions();
versions.unshift(versions[0]);
for (const i in versions) { // On the first version, compare with itself to update it with no changes
const currentVersion = versions[i]; versions.unshift(versions[0]);
const nextVersion = versions[+i + 1];
if (currentVersion === "unreleased") { for (const i in versions) {
return; const currentVersion = versions[i];
} if (currentVersion === "unreleased") return;
const newData = bench.get(nextVersion); const nextVersion = versions[+i + 1];
const oldData = bench.get(currentVersion); const newData = bench.get(nextVersion);
const oldData = bench.get(currentVersion);
// Create table // Create table
const table = Markdown.createTable( const table = Markdown.createTable();
"Instruction",
"Compute Units",
"+/-"
);
bench.compareComputeUnits( bench.compare({
newData.result.computeUnits, newResult: newData.result[resultType],
oldData.result.computeUnits, oldResult: oldData.result[resultType],
({ ixName, newComputeUnits, oldComputeUnits }) => { changeCb: ({ name, newValue, oldValue }) => {
if (newComputeUnits === null) { if (newValue === null) {
// Deleted instruction // Deleted key
return; return;
}
let changeText;
if (oldComputeUnits === null) {
// New instruction
changeText = "N/A";
} else {
const delta = newComputeUnits - oldComputeUnits;
const percentChange = (
(newComputeUnits / oldComputeUnits - 1) *
100
).toFixed(2);
if (+percentChange > 0) {
changeText = `🔴 **+${delta} (${percentChange}%)**`;
} else {
changeText = `🟢 **${delta} (${percentChange.slice(1)}%)**`;
}
}
table.insert(ixName, newComputeUnits.toString(), changeText);
},
(ixName, computeUnits) => {
table.insert(
ixName,
computeUnits.toString(),
+i === 0 ? "N/A" : "-"
);
} }
);
// Update version data let changeText: string;
markdown.updateVersion({ if (oldValue === null) {
version: nextVersion, // New key
solanaVersion: newData.solanaVersion, changeText = "N/A";
table, } else {
}); const delta = (newValue - oldValue).toLocaleString();
} const percentChange = ((newValue / oldValue - 1) * 100).toFixed(2);
if (+percentChange > 0) {
changeText = `🔴 **+${delta} (${percentChange}%)**`;
} else {
changeText = `🟢 **${delta} (${percentChange.slice(1)}%)**`;
}
}
table.insert(name, newValue.toLocaleString(), changeText);
},
noChangeCb: ({ name, value }) => {
table.insert(name, value.toLocaleString(), +i === 0 ? "N/A" : "-");
},
});
// Update version data
markdown.updateVersion({
version: nextVersion,
solanaVersion: newData.solanaVersion,
table,
});
} }
}); });
})(); })();

View File

@ -14,6 +14,7 @@ import {
Toml, Toml,
VersionManager, VersionManager,
runAnchorTest, runAnchorTest,
spawn,
} from "./utils"; } from "./utils";
(async () => { (async () => {
@ -75,4 +76,7 @@ import {
return; return;
} }
} }
// Sync markdown files
spawn("anchor", ["run", "sync-markdown"]);
})(); })();

View File

@ -15,15 +15,23 @@ type Bench = {
*/ */
solanaVersion: Version; solanaVersion: Version;
/** Benchmark results for a version */ /** Benchmark results for a version */
result: { result: BenchResult;
/** Benchmark result for compute units consumed */
computeUnits: ComputeUnits;
};
}; };
}; };
/** Benchmark result per version */
export type BenchResult = {
/** Benchmark result for program binary size */
binarySize: BinarySize;
/** Benchmark result for compute units consumed */
computeUnits: ComputeUnits;
};
/** `program name -> binary size` */
export type BinarySize = { [programName: string]: number };
/** `instruction name -> compute units consumed` */ /** `instruction name -> compute units consumed` */
export type ComputeUnits = { [key: string]: number }; export type ComputeUnits = { [ixName: string]: number };
/** /**
* How much of a percentage difference between the current and the previous data * How much of a percentage difference between the current and the previous data
@ -50,7 +58,7 @@ export class BenchData {
this.#data = data; this.#data = data;
} }
/** Open the benchmark data file */ /** Open the benchmark data file. */
static async open() { static async open() {
let bench: Bench; let bench: Bench;
try { try {
@ -65,86 +73,92 @@ export class BenchData {
return new BenchData(bench); return new BenchData(bench);
} }
/** Save the benchmark data file */ /** Save the benchmark data file. */
async save() { async save() {
await fs.writeFile(BenchData.#PATH, JSON.stringify(this.#data, null, 2)); await fs.writeFile(BenchData.#PATH, JSON.stringify(this.#data, null, 2));
} }
/** Get the stored results based on version */ /** Get the stored results based on version. */
get(version: Version) { get(version: Version) {
return this.#data[version]; return this.#data[version];
} }
/** Get all versions */ /** Get all versions. */
getVersions() { getVersions() {
return Object.keys(this.#data) as Version[]; return Object.keys(this.#data) as Version[];
} }
/** Compare and update compute units changes */ /** Compare benchmark changes. */
compareComputeUnits( compare<K extends keyof BenchResult>({
newComputeUnitsResult: ComputeUnits, newResult,
oldComputeUnitsResult: ComputeUnits, oldResult,
changeCb,
noChangeCb,
treshold = 0,
}: {
/** New bench result */
newResult: BenchResult[K];
/** Old bench result */
oldResult: BenchResult[K];
/** Callback to run when there is a change(considering `threshold`) */
changeCb: (args: { changeCb: (args: {
ixName: string; name: string;
newComputeUnits: number | null; newValue: number | null;
oldComputeUnits: number | null; oldValue: number | null;
}) => void, }) => void;
noChangeCb?: (ixName: string, computeUnits: number) => void /** Callback to run when there is no change(considering `threshold`) */
) { noChangeCb?: (args: { name: string; value: number }) => void;
/** Change threshold percentage(maximum allowed difference between results) */
treshold?: number;
}) {
let needsUpdate = false; let needsUpdate = false;
const executeChangeCb = (...args: Parameters<typeof changeCb>) => {
changeCb(...args);
needsUpdate = true;
};
const checkIxs = ( const compare = (
comparedFrom: ComputeUnits, compareFrom: BenchResult[K],
comparedTo: ComputeUnits, compareTo: BenchResult[K],
cb: (ixName: string, computeUnits: number) => void cb: (name: string, value: number) => void
) => { ) => {
for (const ixName in comparedFrom) { for (const name in compareFrom) {
if (comparedTo[ixName] === undefined) { if (compareTo[name] === undefined) {
cb(ixName, comparedFrom[ixName]); cb(name, compareTo[name]);
} }
} }
}; };
// New instruction // New key
checkIxs( compare(newResult, oldResult, (name, value) => {
newComputeUnitsResult, console.log(`New key '${name}'`);
oldComputeUnitsResult, executeChangeCb({
(ixName, computeUnits) => { name,
console.log(`New instruction '${ixName}'`); newValue: value,
changeCb({ oldValue: null,
ixName, });
newComputeUnits: computeUnits, });
oldComputeUnits: null,
});
needsUpdate = true;
}
);
// Deleted instruction // Deleted key
checkIxs( compare(oldResult, newResult, (name, value) => {
oldComputeUnitsResult, console.log(`Deleted key '${name}'`);
newComputeUnitsResult, executeChangeCb({
(ixName, computeUnits) => { name,
console.log(`Deleted instruction '${ixName}'`); newValue: null,
changeCb({ oldValue: value,
ixName, });
newComputeUnits: null, });
oldComputeUnits: computeUnits,
});
needsUpdate = true;
}
);
// Compare compute units changes // Compare compute units changes
for (const ixName in newComputeUnitsResult) { for (const name in newResult) {
const oldComputeUnits = oldComputeUnitsResult[ixName]; const oldValue = oldResult[name];
const newComputeUnits = newComputeUnitsResult[ixName]; const newValue = newResult[name];
const percentage = THRESHOLD_PERCENTAGE / 100; const percentage = treshold / 100;
const oldMaximumAllowedDelta = oldComputeUnits * percentage; const oldMaximumAllowedDelta = oldValue * percentage;
const newMaximumAllowedDelta = newComputeUnits * percentage; const newMaximumAllowedDelta = newValue * percentage;
const delta = newComputeUnits - oldComputeUnits; const delta = newValue - oldValue;
const absDelta = Math.abs(delta); const absDelta = Math.abs(delta);
if ( if (
@ -155,31 +169,60 @@ export class BenchData {
if (process.env.CI) { if (process.env.CI) {
throw new Error( throw new Error(
[ [
`Compute units for instruction '${ixName}' has changed more than ${THRESHOLD_PERCENTAGE}% but is not saved.`, `Key '${name}' has changed more than ${treshold}% but is not saved.`,
"Run `anchor test --skip-lint` in tests/bench and commit the changes.", "Run `anchor test --skip-lint` in tests/bench and commit the changes.",
].join(" ") ].join(" ")
); );
} }
console.log( console.log(`'${name}' (${oldValue} -> ${newValue})`);
`Compute units change '${ixName}' (${oldComputeUnits} -> ${newComputeUnits})`
);
changeCb({ executeChangeCb({
ixName, name,
newComputeUnits, newValue,
oldComputeUnits, oldValue,
}); });
needsUpdate = true;
} else { } else {
noChangeCb?.(ixName, newComputeUnits); noChangeCb?.({ name, value: newValue });
} }
} }
return { needsUpdate }; return { needsUpdate };
} }
/** Bump benchmark data version to the given version */ /** Compare and update benchmark changes. */
async update(result: Partial<BenchResult>) {
const resultType = Object.keys(result)[0] as keyof typeof result;
const newResult = result[resultType]!;
// Compare and update benchmark changes
const version = getVersionFromArgs();
const oldResult = this.get(version).result[resultType];
const { needsUpdate } = this.compare({
newResult,
oldResult,
changeCb: ({ name, newValue }) => {
if (newValue === null) delete oldResult[name];
else oldResult[name] = newValue;
},
treshold: THRESHOLD_PERCENTAGE,
});
if (needsUpdate) {
console.log("Updating benchmark files...");
// Save bench data file
// (needs to happen before running the `sync-markdown` script)
await this.save();
// Only update markdown files on `unreleased` version
if (version === "unreleased") {
spawn("anchor", ["run", "sync-markdown"]);
}
}
}
/** Bump benchmark data version to the given version. */
bumpVersion(newVersion: string) { bumpVersion(newVersion: string) {
if (this.#data[newVersion]) { if (this.#data[newVersion]) {
throw new Error(`Version '${newVersion}' already exists!`); throw new Error(`Version '${newVersion}' already exists!`);
@ -240,23 +283,23 @@ export class Markdown {
this.#text = text; this.#text = text;
} }
/** Open the markdown file */ /** Open the markdown file. */
static async open(path: string) { static async open(path: string) {
const text = await fs.readFile(path, { encoding: "utf8" }); const text = await fs.readFile(path, { encoding: "utf8" });
return new Markdown(path, text); return new Markdown(path, text);
} }
/** Create a markdown table */ /** Create a markdown table. */
static createTable(...args: string[]) { static createTable(...args: string[]) {
return new MarkdownTable([args]); return new MarkdownTable([args]);
} }
/** Save the markdown file */ /** Save the markdown file. */
async save() { async save() {
await fs.writeFile(this.#path, this.#text); await fs.writeFile(this.#path, this.#text);
} }
/** Change the version's content with the given `solanaVersion` and `table` */ /** Change the version's content with the given `solanaVersion` and `table`. */
updateVersion(params: { updateVersion(params: {
version: Version; version: Version;
solanaVersion: string; solanaVersion: string;
@ -274,17 +317,20 @@ export class Markdown {
const tableStartIndex = const tableStartIndex =
titleStartIndex + md.slice(titleStartIndex).indexOf("|"); titleStartIndex + md.slice(titleStartIndex).indexOf("|");
const tableRowStartIndex =
tableStartIndex + md.slice(tableStartIndex).indexOf("\n");
const tableEndIndex = const tableEndIndex =
tableStartIndex + md.slice(tableStartIndex).indexOf("\n\n"); tableStartIndex + md.slice(tableStartIndex).indexOf("\n\n");
this.#text = this.#text =
md.slice(0, titleContentStartIndex) + md.slice(0, titleContentStartIndex) +
`Solana version: ${params.solanaVersion}\n\n` + `Solana version: ${params.solanaVersion}\n\n` +
md.slice(tableStartIndex, tableRowStartIndex - 1) +
params.table.toString() + params.table.toString() +
md.slice(tableEndIndex + 1); md.slice(tableEndIndex + 1);
} }
/** Bump the version to the given version */ /** Bump the version to the given version. */
bumpVersion(newVersion: string) { bumpVersion(newVersion: string) {
newVersion = `[${newVersion}]`; newVersion = `[${newVersion}]`;
if (this.#text.includes(newVersion)) { if (this.#text.includes(newVersion)) {
@ -342,12 +388,12 @@ class MarkdownTable {
this.insert("-", "-", "-"); this.insert("-", "-", "-");
} }
/** Insert a new row to the markdown table */ /** Insert a new row to the markdown table. */
insert(...args: string[]) { insert(...args: string[]) {
this.#rows.push(args); this.#rows.push(args);
} }
/** Convert the stored rows to a markdown table */ /** Convert the stored rows to a markdown table. */
toString() { toString() {
return this.#rows.reduce( return this.#rows.reduce(
(acc, row) => (acc, row) =>
@ -370,7 +416,7 @@ export class Toml {
this.#text = text; this.#text = text;
} }
/** Open the TOML file */ /** Open the TOML file. */
static async open(tomlPath: string) { static async open(tomlPath: string) {
tomlPath = path.join(__dirname, tomlPath); tomlPath = path.join(__dirname, tomlPath);
const text = await fs.readFile(tomlPath, { const text = await fs.readFile(tomlPath, {
@ -379,12 +425,12 @@ export class Toml {
return new Toml(tomlPath, text); return new Toml(tomlPath, text);
} }
/** Save the TOML file */ /** Save the TOML file. */
async save() { async save() {
await fs.writeFile(this.#path, this.#text); await fs.writeFile(this.#path, this.#text);
} }
/** Replace the value for the given key */ /** Replace the value for the given key. */
replaceValue( replaceValue(
key: string, key: string,
cb: (previous: string) => string, cb: (previous: string) => string,
@ -402,7 +448,7 @@ export class LockFile {
/** Cargo lock file name */ /** Cargo lock file name */
static #CARGO_LOCK = "Cargo.lock"; static #CARGO_LOCK = "Cargo.lock";
/** Replace the Cargo.lock with the given version's cached lock file */ /** Replace the Cargo.lock with the given version's cached lock file. */
static async replace(version: Version) { static async replace(version: Version) {
// Remove Cargo.lock // Remove Cargo.lock
try { try {
@ -416,7 +462,7 @@ export class LockFile {
} }
} }
/** Cache the current Cargo.lock in ./locks */ /** Cache the current Cargo.lock in `./locks`. */
static async cache(version: Version) { static async cache(version: Version) {
try { try {
await fs.rename(this.#CARGO_LOCK, this.#getLockPath(version)); await fs.rename(this.#CARGO_LOCK, this.#getLockPath(version));
@ -434,7 +480,7 @@ export class LockFile {
} }
} }
/** Get the lock file path from the given version */ /** Get the lock file path from the given version. */
static #getLockPath(version: Version) { static #getLockPath(version: Version) {
return path.join("locks", `${version}.lock`); return path.join("locks", `${version}.lock`);
} }
@ -442,7 +488,7 @@ export class LockFile {
/** Utility class to manage versions */ /** Utility class to manage versions */
export class VersionManager { export class VersionManager {
/** Set the active Solana version with `solana-install init` command */ /** Set the active Solana version with `solana-install init` command. */
static setSolanaVersion(version: Version) { static setSolanaVersion(version: Version) {
const activeVersion = this.#getSolanaVersion(); const activeVersion = this.#getSolanaVersion();
if (activeVersion === version) return; if (activeVersion === version) return;
@ -453,7 +499,7 @@ export class VersionManager {
}); });
} }
/** Get the active Solana version */ /** Get the active Solana version. */
static #getSolanaVersion() { static #getSolanaVersion() {
// `solana-cli 1.14.16 (src:0fb2ffda; feat:3488713414)\n` // `solana-cli 1.14.16 (src:0fb2ffda; feat:3488713414)\n`
const result = execSync("solana --version"); const result = execSync("solana --version");
@ -476,12 +522,12 @@ export const getVersionFromArgs = () => {
: (args[anchorVersionArgIndex + 1] as Version); : (args[anchorVersionArgIndex + 1] as Version);
}; };
/** Run `anchor test` command */ /** Run `anchor test` command. */
export const runAnchorTest = () => { export const runAnchorTest = () => {
return spawn("anchor", ["test", "--skip-lint"]); return spawn("anchor", ["test", "--skip-lint"]);
}; };
/** Spawn a blocking process */ /** Spawn a blocking process. */
export const spawn = ( export const spawn = (
cmd: string, cmd: string,
args: string[], args: string[],

View File

@ -0,0 +1,19 @@
import * as fs from "fs/promises";
import path from "path";
import { IDL } from "../target/types/bench";
import { BenchData, BinarySize } from "../scripts/utils";
describe("Binary size", () => {
const binarySize: BinarySize = {};
it(`Measure binary size of program '${IDL.name}'`, async () => {
const stat = await fs.stat(path.join("target", "deploy", `${IDL.name}.so`));
binarySize[IDL.name] = stat.size;
});
after(async () => {
const bench = await BenchData.open();
await bench.update({ binarySize });
});
});

View File

@ -9,7 +9,7 @@ import {
spawn, spawn,
} from "../scripts/utils"; } from "../scripts/utils";
describe(IDL.name, () => { describe("Compute units", () => {
// Configure the client to use the local cluster // Configure the client to use the local cluster
anchor.setProvider(anchor.AnchorProvider.env()); anchor.setProvider(anchor.AnchorProvider.env());
@ -115,8 +115,6 @@ describe(IDL.name, () => {
}; };
before(async () => { before(async () => {
// TODO: Check Solana version
// Create necessary accounts // Create necessary accounts
const tokenProgram = token.splTokenProgram({ const tokenProgram = token.splTokenProgram({
provider: anchor.AnchorProvider.local(), provider: anchor.AnchorProvider.local(),
@ -229,35 +227,7 @@ describe(IDL.name, () => {
}); });
after(async () => { after(async () => {
// Read the bench data file
const bench = await BenchData.open(); const bench = await BenchData.open();
await bench.update({ computeUnits });
// Compare and update compute units changes
const version = getVersionFromArgs();
const oldComputeUnits = bench.get(version).result.computeUnits;
const { needsUpdate } = bench.compareComputeUnits(
computeUnits,
oldComputeUnits,
({ ixName, newComputeUnits: newValue }) => {
if (newValue === null) {
delete oldComputeUnits[ixName];
} else {
oldComputeUnits[ixName] = newValue;
}
}
);
if (needsUpdate) {
console.log("Updating benchmark files...");
// Save bench data file
// (needs to happen before running the `sync-markdown` script)
await bench.save();
// Only update markdown files on `unreleased` version
if (version === "unreleased") {
spawn("anchor", ["run", "sync-markdown"]);
}
}
}); });
}); });