Book a free call

Solana Optimization: Best Practices for Faster Programs

Solana programs run inside a strict compute budget, so small design choices decide whether a transaction succeeds or fails. These practices keep programs fast.

Hertiv engineering teamReviewed by a senior engineer
7 min read
Solana Optimization: Best Practices for Faster Programs
On this page

Short answer

Solana optimization means designing programs and transactions to use less compute, fewer accounts and less data, so they fit inside Solana's per-transaction limits and confirm quickly. The main levers are compute-unit budgets, compact account design, fewer signatures and careful use of priority fees. Measure compute use before launch, because a program that works on a local validator can still fail under real network load.

What does Solana optimization mean?

Solana optimization is the practice of making programs and transactions use fewer resources so they run faster, cost less and fail less often. Solana charges for compute units, limits how much work one transaction can do, and expects programs to finish quickly, so wasted work shows up directly as failed transactions and higher fees.

Three limits shape every optimization decision. A transaction can use at most 1,400,000 compute units. A transaction has a size limit, so it can only carry so many accounts and instructions. And the network processes transactions in order, so a program that takes too long holds up everything behind it. Optimization is the work of fitting inside those limits with room to spare.

The goal is not to squeeze out every last unit. The goal is a program that stays well inside the limits under real load, including busy periods when the network is congested. A program that uses 300,000 compute units on a quiet test network but 900,000 when accounts are large and data is messy is not optimized.

A program that uses 200,000 units in both cases is. The guide to building on Solana covers the basics; this article covers how to make what you build run well.

How do compute units shape performance?

Compute units are Solana's measure of work. Every instruction in a program costs units, and a transaction fails if its instructions need more than 1,400,000 units in total. That hard cap is the first thing to design around.

Start by measuring. Solana's tools report how many compute units each instruction uses, so run your program against realistic data and record the numbers. Set a compute budget in your transactions that matches what you measured, with a margin for variation. A budget that is far above what you need wastes nothing on its own, but it hides the point where your program would start failing, so keep the budget close to measured use.

Priority fees buy a place in line when the network is busy. They do not buy more compute units, and they do not fix a program that needs more than the cap allows. Use them for transactions that must land quickly, such as payments, and set them based on current network conditions rather than a fixed number.

A fee that is right during quiet hours can be far too low during a busy launch. Keep the expensive work out of the program where you can: do calculations off-chain and pass the result in, rather than computing it on-chain for every transaction.

How should you design accounts and data?

Accounts are where Solana programs store data, and their design decides how much work each transaction does. Large accounts cost more to read and write, and accounts that many transactions touch at once create contention that slows the whole program down.

PracticeWhat it changesWhen it matters most
Keep accounts smallLess data read and written per callHigh-frequency updates
Split hot accountsSpreads writes across accountsMany users writing at once
Store fixed-size fieldsPredictable layout and costEvery program
Move big data off-chainOnly a reference lives on-chainImages, documents, logs
Close unused accountsFrees rent and reduces clutterTemporary or finished state

Fixed-size fields deserve special attention. A field that can grow without a bound makes compute use unpredictable, because the same instruction costs more as the data grows. Set a maximum size for every variable-length field and reject input that would exceed it.

For data that is too large to store on-chain, such as images or long documents, store a hash or a link on-chain and keep the data elsewhere. That keeps the account small while still letting anyone verify the data matches the reference.

How do you cut transaction costs and failures?

Transaction costs on Solana come from fees, and failures usually come from size, compute or stale state. Most of both can be designed away before launch.

  • Use versioned transactions and lookup tables. Address lookup tables let a transaction reference many accounts without carrying every address, which keeps transactions small and leaves room for more instructions.
  • Batch work into fewer transactions. One transaction that does several related steps costs less in fees and confirms more reliably than many small ones, as long as it stays inside the compute and size limits.
  • Keep signatures to a minimum. Each signature adds size and cost, so do not ask users to sign for data the program can already verify.
  • Handle stale state. Accounts change between the time you read them and the time your transaction runs. Design for retries and check the result after each attempt instead of assuming success.
  • Set sensible priority fees. Check current network conditions and set fees that match them, rather than a fixed value that is wrong half the time.

Retries need care. A failed transaction that is retried blindly can run the same instruction twice and charge twice, so make instructions safe to repeat where possible and confirm the result before retrying. When you implement Solana in an existing app, build the retry and confirmation logic into the client from the start rather than adding it after the first outage.

How do you test and measure before launch?

You test and measure Solana programs by running them against realistic data and load before real users depend on them. A program that works on a local validator with tiny test accounts has proved very little.

  1. Measure compute on real data. Run every instruction against production-sized accounts and record the compute units. Note the worst case, not the average.
  2. Load test with many users. Simulate many transactions at once to find contention on shared accounts and to see how the program behaves when the network is busy.
  3. Test on devnet, then on mainnet with small amounts. Devnet catches logic errors; a small mainnet trial catches the costs and conditions that devnet cannot reproduce.
  4. Simulate before sending. Use transaction simulation to check that a transaction will succeed before you send it, especially for large or multi-step transactions.
  5. Monitor after launch. Track compute use, failure rates and fee spend per transaction, and set alerts for sudden changes.

Keep the measurements in a place the whole team can see, and re-run them after every significant change. A small change to an account layout can shift compute use a lot, and the only way to catch it is to measure again. Upgrades to the network can also change costs, so watch the Solana upgrade notes for changes that affect your program.

Example (hypothetical): a payments app cuts compute use

Example (hypothetical): a payments app processes transfers on Solana. Each transfer uses 200,000 compute units, and the app wants to pack several transfers into one transaction. The limit is 1,400,000 units, so 1,400,000 divided by 200,000 gives 7 transfers per transaction.

The team profiles the program and finds two easy wins. First, it moves a price calculation off-chain and passes the result in, which saves 50,000 units per transfer. Second, it shrinks the account layout so each transfer reads less data, saving another 30,000 units. Each transfer now uses 120,000 units, so 1,400,000 divided by 120,000 gives 11 transfers per transaction, with 80,000 units to spare.

The result is fewer transactions for the same volume: 1,100 transfers need about 157 transactions at 7 per transaction, but only 100 at 11 per transaction. Fees fall by roughly a third, and the app confirms payments faster during busy periods because each transaction carries more work. The team keeps the compute budget set to 130,000 units per transfer, which leaves a margin above the measured 120,000 without hiding a future regression.

What are the common mistakes?

The most common Solana optimization mistakes are ignoring compute measurement, designing accounts that everyone writes to at once, and trusting a local test to prove production behaviour.

  • Never measuring compute. If you do not know how many units each instruction uses, you cannot know how close you are to the 1,400,000 cap.
  • One hot account for everything. A single account that every transaction writes to becomes a bottleneck. Split state across accounts.
  • Unbounded fields. A list or string that can grow without a limit makes compute use unpredictable and can push a transaction over the cap.
  • Computing on-chain what belongs off-chain. Heavy calculations inside the program waste units on work the client could have done once.
  • Fixed priority fees. A fee set once and never reviewed is too low during busy periods and too high during quiet ones.
  • No retry plan. Transactions fail for stale state and congestion. Without safe retries and result checks, users pay for work that never lands.

Key takeaways

  • A Solana transaction can use at most 1,400,000 compute units, so measure every instruction
  • Small, fixed-size accounts and split hot accounts cut both compute use and contention
  • Versioned transactions and lookup tables keep transactions small enough to carry more work
  • Do heavy calculations off-chain and pass the result in instead of computing it on-chain
  • Test on realistic data and load, simulate before sending, and monitor compute use after launch

Frequently asked questions

What is the compute unit limit on Solana?

One transaction can use at most 1,400,000 compute units. If your instructions need more, the transaction fails, so measure compute use on realistic data and design the program to stay well under the cap, with a margin for variation.

Do priority fees make a transaction faster?

Priority fees help a transaction get processed sooner when the network is busy, but they do not raise the compute limit or fix a program that needs more units than allowed. Use them for time-sensitive transactions and set them from current network conditions.

What are address lookup tables?

Address lookup tables let a versioned transaction reference accounts by a short index instead of carrying the full address for each one. That keeps transactions small, leaves room for more instructions, and is one of the simplest ways to fit more work into a transaction.

Why does my program work locally but fail on mainnet?

Local tests usually use small accounts and quiet conditions, while mainnet has larger accounts, more contention and real congestion. Measure compute on production-sized data, load test with many users, and try a small mainnet run before a full launch.

Should I store large files on Solana?

No. Store a hash or a reference on-chain and keep the file itself elsewhere. Large on-chain data makes accounts expensive to read and write, and it pushes transactions toward the size and compute limits for no benefit.

How do I reduce Solana transaction fees?

Batch related steps into fewer transactions, keep signatures to a minimum, use lookup tables to keep transactions small, and set priority fees from current conditions rather than a fixed value. The biggest savings usually come from using less compute per transaction.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building on Solana and want programs that stay fast under load? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Solana Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call