Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench: Add benchmarking for stack memory usage #2617

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
307 changes: 307 additions & 0 deletions bench/STACK_MEMORY.md

Large diffs are not rendered by default.

267 changes: 267 additions & 0 deletions tests/bench/bench.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,95 @@
"uncheckedAccount2": 1567,
"uncheckedAccount4": 2060,
"uncheckedAccount8": 3855
},
"stackMemory": {
"account_info1": 248,
"account_info2": 392,
"account_info4": 512,
"account_info8": 896,
"account_empty_init1": 584,
"account_empty_init2": 512,
"account_empty_init4": 704,
"account_empty_init8": 1088,
"account_empty1": 200,
"account_empty2": 344,
"account_empty4": 464,
"account_empty8": 848,
"account_sized_init1": 592,
"account_sized_init2": 544,
"account_sized_init4": 768,
"account_sized_init8": 1216,
"account_sized1": 200,
"account_sized2": 360,
"account_sized4": 528,
"account_sized8": 976,
"account_unsized_init1": 608,
"account_unsized_init2": 608,
"account_unsized_init4": 896,
"account_unsized_init8": 1472,
"account_unsized1": 176,
"account_unsized2": 392,
"account_unsized4": 656,
"account_unsized8": 1232,
"boxed_account_empty_init1": 544,
"boxed_account_empty_init2": 408,
"boxed_account_empty_init4": 424,
"boxed_account_empty_init8": 456,
"boxed_account_empty1": 240,
"boxed_account_empty2": 248,
"boxed_account_empty4": 280,
"boxed_account_empty8": 312,
"boxed_account_sized_init1": 544,
"boxed_account_sized_init2": 408,
"boxed_account_sized_init4": 424,
"boxed_account_sized_init8": 456,
"boxed_account_sized1": 240,
"boxed_account_sized2": 248,
"boxed_account_sized4": 280,
"boxed_account_sized8": 312,
"boxed_account_unsized_init1": 544,
"boxed_account_unsized_init2": 408,
"boxed_account_unsized_init4": 424,
"boxed_account_unsized_init8": 456,
"boxed_account_unsized1": 248,
"boxed_account_unsized2": 248,
"boxed_account_unsized4": 280,
"boxed_account_unsized8": 312,
"boxed_interface_account_mint1": 240,
"boxed_interface_account_mint2": 248,
"boxed_interface_account_mint4": 280,
"boxed_interface_account_mint8": 312,
"boxed_interface_account_token1": 240,
"boxed_interface_account_token2": 248,
"boxed_interface_account_token4": 280,
"boxed_interface_account_token8": 312,
"interface_account_mint1": 208,
"interface_account_mint2": 752,
"interface_account_mint4": 1424,
"interface_account_mint8": 2768,
"interface_account_token1": 264,
"interface_account_token2": 1104,
"interface_account_token4": 2128,
"interface1": 200,
"interface2": 344,
"interface4": 464,
"interface8": 848,
"program1": 200,
"program2": 344,
"program4": 464,
"program8": 848,
"signer1": 248,
"signer2": 392,
"signer4": 512,
"signer8": 896,
"system_account1": 248,
"system_account2": 392,
"system_account4": 512,
"system_account8": 896,
"unchecked_account1": 248,
"unchecked_account2": 392,
"unchecked_account4": 512,
"unchecked_account8": 896
}
}
},
Expand Down Expand Up @@ -190,6 +279,95 @@
"uncheckedAccount2": 1475,
"uncheckedAccount4": 1965,
"uncheckedAccount8": 3841
},
"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,
"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": 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
}
}
},
Expand Down Expand Up @@ -287,6 +465,95 @@
"uncheckedAccount2": 1475,
"uncheckedAccount4": 1965,
"uncheckedAccount8": 3841
},
"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,
"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": 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
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/bench/scripts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import {

// Run the command to update the current version's results
const result = runAnchorTest();
console.log(result.output.toString());

// Check failure
if (result.status !== 0) {
Expand Down
7 changes: 6 additions & 1 deletion tests/bench/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type BenchResult = {
binarySize: BinarySize;
/** Benchmark result for compute units consumed */
computeUnits: ComputeUnits;
/** Benchmark result for stack memory usage */
stackMemory: StackMemory;
};

/** `program name -> binary size` */
Expand All @@ -33,6 +35,9 @@ export type BinarySize = { [programName: string]: number };
/** `instruction name -> compute units consumed` */
export type ComputeUnits = { [ixName: string]: number };

/** `instruction name -> stack memory used` */
export type StackMemory = { [ixName: string]: number };

/**
* How much of a percentage difference between the current and the previous data
* should be significant. Any difference above this number should be noted in
Expand Down Expand Up @@ -124,7 +129,7 @@ export class BenchData {
) => {
for (const name in compareFrom) {
if (compareTo[name] === undefined) {
cb(name, compareTo[name]);
cb(name, compareFrom[name]);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/tests/binary-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BenchData, BinarySize } from "../scripts/utils";
describe("Binary size", () => {
const binarySize: BinarySize = {};

it(`Measure binary size of program '${IDL.name}'`, async () => {
it("Measure binary size", async () => {
const stat = await fs.stat(path.join("target", "deploy", `${IDL.name}.so`));
binarySize[IDL.name] = stat.size;
});
Expand Down
7 changes: 1 addition & 6 deletions tests/bench/tests/compute-units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import * as anchor from "@coral-xyz/anchor";
import * as token from "@coral-xyz/spl-token";

import { Bench, IDL } from "../target/types/bench";
import {
BenchData,
ComputeUnits,
getVersionFromArgs,
spawn,
} from "../scripts/utils";
import { BenchData, ComputeUnits } from "../scripts/utils";

describe("Compute units", () => {
// Configure the client to use the local cluster
Expand Down
Loading
Loading