Performance of empty function on Dart

1,507

Solution 1

The compiler will optimize your code through inlining and removing calls to empty functions.

Solution 2

will this function be removed on build?

Not unless you use it only within other asserts. A typical example would be this:

assert(() {
  test();
  return true;
}());

If you only use it this way, then yes the function will be removed on build.

Share:
1,507
selharxets
Author by

selharxets

Updated on December 07, 2022

Comments

  • selharxets
    selharxets 11 months

    Let say I have this code:

    void test(){
     assert(() {
       print("This is Test");
     });
    }
    

    As per this question, dart will remove assert on production build

    but how about test() function which being called?

    will this function be removed on build?

    or will this have any significant impact on performance if I call empty function multiple times?