Speed Up Your Flutter Code with Inline Compilation

Gautier Siclon
Gautier Siclon

Co-founder, Apparence.io

Flutter tips · Published on

Want to make your Dart or Flutter code run a little faster? There's a useful tip involving how your code gets turned into machine code.

Use @pragma('vm:prefer-inline')

Put @pragma('vm:prefer-inline') just before a function definition. This is a hint to the Dart Virtual Machine (VM) compiler. It suggests that you'd prefer this function to be 'inlined'.

What Does Inlining Mean?

Inlining is like copying the code inside a function and pasting it directly where that function is called. Instead of the program jumping to a separate spot for the function and then returning, it just runs the code right there.

Benefits of Inlining

Avoiding the function call jump can sometimes make the code run faster. It can be especially helpful for small functions that are called over and over again.

How the Compiler Uses It

The compiler looks at your code and uses this pragma as a suggestion. It decides if inlining is actually a good idea based on different factors. If it decides to inline the function, the final machine code will have the function's logic placed directly in the calling spot, as shown in the image example. This can lead to more efficient execution.

Save 3 months of work

One command. Pick your modules. Firebase or Supabase auto-configured. Start building what matters.

kickstarter for flutter apps

Frequently Asked Questions

What is @pragma('vm:prefer-inline')?

It's a special note (pragma) you add before a function in Dart. It tells the Dart VM compiler that you would prefer this function to be inlined.

Does using this pragma guarantee faster code?

No, it's a suggestion to the compiler, not a command. The compiler will decide if inlining is beneficial and safe for that specific function.

Should I use this on all my functions?

It's generally most effective for small functions that are called frequently. Using it on large functions might not help and could potentially increase the size of your compiled code.

Read more
You may also be interested in
Made by ApparenceKit logo
ApparenceKit is a flutter start kit | template generator tool by Apparence.io © 2026.
All rights reserved