Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http download is 3x times slower on Web vs Desktop #1175

Open
tomekit opened this issue Apr 9, 2024 · 0 comments
Open

Http download is 3x times slower on Web vs Desktop #1175

tomekit opened this issue Apr 9, 2024 · 0 comments
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@tomekit
Copy link

tomekit commented Apr 9, 2024

Steps to reproduce

Run code: flutter run --release on Web then click a button, it will download ~18MB file.
Repeat tests on non-web (e.g. desktop platform), download speed shall be much higher.

On my ~40Mbps download connection, Linux maxes out download speed.
On Web speed seem to be throttled for some reason.

Linux

Download file https://cjx45haf.s3.kapsa.io/d4c0f74e-9ef9-40c6-aa27-e2e4bdeafe34/file_example_MP4_1920_18MG.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=1C6RoVNL9skDTFN1A%2F20240409%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240409T093551Z&X-Amz-Expires=604798&X-Amz-SignedHeaders=host&X-Amz-Signature=4fa81af1530666dbed1e942e63e888f7b221c4e1a41f482d1d642798fd1e3824
flutter: Downloaded 17839845 in 3603ms

Web

Download file https://cjx45haf.s3.kapsa.io/d4c0f74e-9ef9-40c6-aa27-e2e4bdeafe34/file_example_MP4_1920_18MG.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=1C6RoVNL9skDTFN1A%2F20240409%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240409T093551Z&X-Amz-Expires=604798&X-Amz-SignedHeaders=host&X-Amz-Signature=4fa81af1530666dbed1e942e63e888f7b221c4e1a41f482d1d642798fd1e3824
Downloaded 17839845 in 11907ms

Code sample

Code sample
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

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> {
  void activateDownload() async {
    final url = 'https://cjx45haf.s3.kapsa.io/d4c0f74e-9ef9-40c6-aa27-e2e4bdeafe34/file_example_MP4_1920_18MG.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=1C6RoVNL9skDTFN1A%2F20240409%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240409T093551Z&X-Amz-Expires=604798&X-Amz-SignedHeaders=host&X-Amz-Signature=4fa81af1530666dbed1e942e63e888f7b221c4e1a41f482d1d642798fd1e3824';

    List<int> buffer = [];
    print('\n1) downloadBytesSimple');
    print('\nDownload file $url');
    await downloadBytesSimple(buffer, url);
  }

  static Future<void> downloadBytesSimple(List<int> buffer, String url) async {
    var headers = {
      'Cache-Control': 'no-cache'
    };

    var startTime = DateTime.timestamp();
    final response = await http.get(Uri.parse(url), headers: headers);
    print('Downloaded ${response.contentLength} in ${DateTime.timestamp().difference(startTime).inMilliseconds}ms');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: const Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('You have pushed the button this many times:'),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          activateDownload();
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

What target platforms are you seeing this bug on?

Web

OS/Browser name and version | Device information

Version 123.0.6312.58 (Official Build) (64-bit)
Ubuntu 23.10

Does the problem occur on emulator/simulator as well as on physical devices?

Yes

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.5, on Ubuntu 23.10 6.5.0-27-generic, locale en_US.UTF-8)
    • Flutter version 3.19.5 on channel stable at /opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (12 days ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/tomek/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /home/tomek/Android/Sdk
    • Java binary at: /opt/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • Ubuntu clang version 16.0.6 (15)
    • cmake version 3.27.4
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2023.1)
    • Android Studio at /opt/android-studio
    • Flutter plugin version 76.3.3
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.78.2)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 23.10 6.5.0-27-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 123.0.6312.58

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Originally posted here: flutter/flutter#146494

@tomekit tomekit added package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:http type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

1 participant