-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench: Add benchmarking for program binary size (#2591)
- Loading branch information
1 parent
abfdc4e
commit 4cf447a
Showing
8 changed files
with
528 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | | ||
|
||
--- |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,69 @@ | ||
/** Sync Markdown files in /bench based on the data from bench.json */ | ||
|
||
import { BenchData, Markdown } from "./utils"; | ||
import { BenchData, BenchResult, Markdown } from "./utils"; | ||
|
||
(async () => { | ||
const bench = await BenchData.open(); | ||
|
||
await BenchData.forEachMarkdown((markdown, fileName) => { | ||
if (fileName === "COMPUTE_UNITS.md") { | ||
const versions = bench.getVersions(); | ||
const resultType = fileName | ||
.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 | ||
versions.unshift(versions[0]); | ||
const versions = bench.getVersions(); | ||
|
||
for (const i in versions) { | ||
const currentVersion = versions[i]; | ||
const nextVersion = versions[+i + 1]; | ||
// On the first version, compare with itself to update it with no changes | ||
versions.unshift(versions[0]); | ||
|
||
if (currentVersion === "unreleased") { | ||
return; | ||
} | ||
for (const i in versions) { | ||
const currentVersion = versions[i]; | ||
if (currentVersion === "unreleased") return; | ||
|
||
const newData = bench.get(nextVersion); | ||
const oldData = bench.get(currentVersion); | ||
const nextVersion = versions[+i + 1]; | ||
const newData = bench.get(nextVersion); | ||
const oldData = bench.get(currentVersion); | ||
|
||
// Create table | ||
const table = Markdown.createTable( | ||
"Instruction", | ||
"Compute Units", | ||
"+/-" | ||
); | ||
// Create table | ||
const table = Markdown.createTable(); | ||
|
||
bench.compareComputeUnits( | ||
newData.result.computeUnits, | ||
oldData.result.computeUnits, | ||
({ ixName, newComputeUnits, oldComputeUnits }) => { | ||
if (newComputeUnits === null) { | ||
// Deleted instruction | ||
return; | ||
} | ||
bench.compare({ | ||
newResult: newData.result[resultType], | ||
oldResult: oldData.result[resultType], | ||
changeCb: ({ name, newValue, oldValue }) => { | ||
if (newValue === null) { | ||
// Deleted key | ||
return; | ||
} | ||
|
||
let changeText; | ||
if (oldComputeUnits === null) { | ||
// New instruction | ||
changeText = "N/A"; | ||
} else { | ||
const delta = newComputeUnits - oldComputeUnits; | ||
const percentChange = ( | ||
(newComputeUnits / oldComputeUnits - 1) * | ||
100 | ||
).toFixed(2); | ||
let changeText: string; | ||
if (oldValue === null) { | ||
// New key | ||
changeText = "N/A"; | ||
} 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)}%)**`; | ||
} | ||
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 | ||
markdown.updateVersion({ | ||
version: nextVersion, | ||
solanaVersion: newData.solanaVersion, | ||
table, | ||
}); | ||
} | ||
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, | ||
}); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4cf447a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
anchor-docs – ./
anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com