Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Increases account hash's stack buffer to hold 200 bytes of data#35394

Closed
brooksprumo wants to merge 1 commit intosolana-labs:masterfrom
brooksprumo:hash/stack-buffer-size
Closed

Increases account hash's stack buffer to hold 200 bytes of data#35394
brooksprumo wants to merge 1 commit intosolana-labs:masterfrom
brooksprumo:hash/stack-buffer-size

Conversation

@brooksprumo
Copy link
Copy Markdown
Contributor

@brooksprumo brooksprumo commented Mar 1, 2024

Problem

When hashing an account, we create a buffer on the stack to reduce the number of unique hash calls to make. The buffer is currently 128 bytes. The metadata fields occupy 81 bytes, which leaves 47 bytes for the account's data.

On mnb today there is approximately 431 million accounts. Of that, approximately 388 million are token accounts. That's 90% of accounts. We should ensure the stack buffer can hold the account data for a token account.

Token accounts have a size of 165 bytes1. This size will be growing though. ATA and Token22 extensions will be larger too. Jon estimates 170-182 bytes is "safe"2.

Also, there are ~1 million stake accounts. They are 200 bytes.

We could size the stack buffer to hold 200 bytes, which will cover the vast majority of accounts. Currently, the vast majority of calls to hash an account have to perform a heap allocation.

TODO: metrics before and after

Summary of Changes

Increases account hash's stack buffer to hold 200 bytes of data

Footnotes

  1. https://github.com/solana-labs/solana-program-library/blob/e651623033fca7997ccd21e55d0f2388473122f9/token/program/src/state.rs#L134

  2. https://discord.com/channels/428295358100013066/977244255212937306/1212827836281524224

@brooksprumo brooksprumo added the work in progress This isn't quite right yet label Mar 1, 2024
@brooksprumo brooksprumo self-assigned this Mar 1, 2024
@brooksprumo brooksprumo force-pushed the hash/stack-buffer-size branch from db9183f to 41fd838 Compare March 1, 2024 19:28
@brooksprumo brooksprumo removed the work in progress This isn't quite right yet label Mar 1, 2024
@brooksprumo brooksprumo force-pushed the hash/stack-buffer-size branch from 41fd838 to 6716fa6 Compare March 1, 2024 19:29
@willhickey
Copy link
Copy Markdown
Contributor

This repository is no longer in use. Please re-open this pull request in the agave repo: https://github.com/anza-xyz/agave

@willhickey willhickey closed this Mar 3, 2024
@brooksprumo brooksprumo deleted the hash/stack-buffer-size branch March 4, 2024 15:37
@brooksprumo
Copy link
Copy Markdown
Contributor Author

Moved to anza-xyz#56

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants