Speed Up Your Flutter Code with Inline Compilation

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

Create your app using our 6 years of making Flutter apps and more than 50+ apps

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
Flutter tips: how to create a responsive layout  blog card image
Flutter tips: how to create a responsive layout
Published on 2025-05-03
6 ways to copy a list or map in dart  blog card image
6 ways to copy a list or map in dart
Published on 2025-05-12T11:41:57.081Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved