solana-program / create-solana-program

pnpm create solana-program
Apache License 2.0
70 stars 9 forks source link

improve Rust close-account fn performance #42

Closed samuelvanderwaal closed 4 months ago

samuelvanderwaal commented 4 months ago

This adds a minor performance improvement to the close_account function in the Shank example Counter Program utils file. Instead of filling the account with zeros, a more efficient way to close accounts is to reassign to the system program and then realloc the length to zero. This is how Anchor does it, for example.

changeset-bot[bot] commented 4 months ago

🦋 Changeset detected

Latest commit: 7d0c49f0433ecd3bf57f984b0d0d645e6bbd03a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | --------------------- | ----- | | create-solana-program | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

lorisleiva commented 4 months ago

Nice, thanks for improving the program template!

It looks like we currently don't import the system-program crate though so we get the following error when we try and cargo check the generated program.

Should we add this to the program's Cargo.toml? Or should we just inline the ID here?

CleanShot 2024-05-16 at 11 49 47@2x

samuelvanderwaal commented 4 months ago

Nice, thanks for improving the program template!

It looks like we currently don't import the system-program crate though so we get the following error when we try and cargo check the generated program.

Should we add this to the program's Cargo.toml? Or should we just inline the ID here?

CleanShot 2024-05-16 at 11 49 47@2x

The Cargo.toml already has the solana_program crate which is where system_program module comes from so I just needed to add it to the utils.rs import statement. The commit I just pushed should fix the issue.

lorisleiva commented 4 months ago

Oh I see! Awesome, just waiting for CI to pass and then I'll merge and publish a new release.