Performance of empty function on Dart

Viewed 1637

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?

2 Answers

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

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.

Related