2

I know that printing a lot can make some Python code run slower (I've tested it and referenced this question). However, I'm not sure if printing a lot makes some Flutter code run slower.

I didn't include the code because I don't think code has anything to do with this and I don't have the code to test it.

Feel free to leave a comment if you need more information.

Does printing a lot make some Flutter code run slower? I would appreciate any help. Thank you in advance!

My Car
  • 4,198
  • 5
  • 17
  • 50
  • yes flutter did not recommend to use print in production code – Ali Hassan Jan 14 '23 at 07:19
  • I personally think that it depends what you mean by "running slower". I didn't use flutter but generally we can say that every line of code in every programming language costs some computation power, nothing is free - I mean it needs to write the content in some output stream under the hood. And it also depends what kind of expressions you are logging and how many strings you concat and so on. Easiest would be that you measure some private methods with and without the prints to answer your question – Radu M Jan 14 '23 at 07:52
  • Why are you concerned about performance issues caused by print in debug mode? Print is not used in production code so will have not impact on the final performance of the app. – GrahamD Jan 14 '23 at 07:53

2 Answers2

1

Well, we preferably use print() in debug mode only. By default, print is disabled in release build of your app, if I'm correct. Unless you call print in loop for over thousand times, it wouldn't have much of an impact on average phones

Delwinn
  • 891
  • 4
  • 19
  • Hi, thanks for your answer. It didn't print more than a thousand times. What if it just prints multiple but each print is very long? – My Car Jan 14 '23 at 07:23
  • it'll only impact your debug performance because when you `release` the app, or run in `release` mode, Flutter will by default ignore print statements. – Delwinn Jan 14 '23 at 10:33
  • Hello, thanks! Ok I will listen to your opinion – My Car Jan 14 '23 at 22:01
1

Flutter does not recommends print() in release mode

Juse use as below code

  void prints(var s) {
    if (kDebugMode) {
      print(s);
    }
  }
Anand
  • 4,355
  • 2
  • 35
  • 45