Repository: flutter
Issue: iOS print() is so slow it cause Lost connection to device in Debug mode
Labels: platform-ios,perf: speed,has reproducible steps,P2,c: fatal crash,team-ios,triaged-ios,found in release: 3.13,found in release: 3.14

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Run example in debug mode

### Expected results

Print log

### Actual results

Lost connection to device.

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  @override
  void initState() {
    super.initState();
    test();
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
    test();
  }

  void Function(Object object) logPrint = print;

  test() {
    String msg = "";
    final now =DateTime.now();
    for (int i=0; i < 100; i++) {
      msg += "$now" * 500;
      msg += "\n";
    }
    msg.toString().split('\n').forEach(logPrint);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

```

</details>


### Screenshots or Video

_No response_

### Logs

<details><summary>Logs</summary>

```console
11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.8574342023-09-06 11:18:57.857434
Lost connection to device.


```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
flutter doctor --verbose
[!] Flutter (Channel stable, 3.13.2, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
    • Flutter version 3.13.2 on channel stable at /Users/xuantung/Desktop/Develop/flutter/3.13.2/flutter
    ! Warning: `flutter` on your path resolves to /Users/xuantung/Desktop/Develop/flutter/3.3.10/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/xuantung/Desktop/Develop/flutter/3.13.2/flutter. Consider adding /Users/xuantung/Desktop/Develop/flutter/3.13.2/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/xuantung/Desktop/Develop/flutter/3.3.10/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/xuantung/Desktop/Develop/flutter/3.13.2/flutter. Consider adding /Users/xuantung/Desktop/Develop/flutter/3.13.2/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff5b5b5fa6 (13 days ago), 2023-08-24 08:12:28 -0500
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/xuantung/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.81.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
    • SM A235F (mobile) • R58W2095NQK               • android-arm64  • Android 13 (API 33)
    • iPhone (mobile)   • 00008020-000110AC3ED0003A • ios            • iOS 16.6 20G75
    • macOS (desktop)   • macos                     • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
    • Chrome (web)      • chrome                    • web-javascript • Google Chrome 116.0.5845.179

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
```

</details>