Closed
Description
UTF8.decode seems surprisingly slow for large buffers.
Using this Flutter program:
import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';
import 'package:flutter/services.dart';
Future<Null> main() async {
ByteData data = await rootBundle.load('LICENSE');
for (int i = 1024; i < data.lengthInBytes; i += 1024) {
final Stopwatch watch = new Stopwatch()..start();
UTF8.decode(data.buffer.asUint8List(0, i));
int time = watch.elapsedMilliseconds;
print('${"$i bytes".padLeft(15)} ${"${time}ms".padLeft(10)} ${(1000 / 1024 * i / time).toStringAsFixed(1)} KB per second');
}
}
...I find that on a Pixel 2 XL, 4KB is parsed in about 1ms, 40KB in about 12ms, and 400KB in about 135ms. This is only about 3MB per second. Then again, I'm not sure what would be considered good throughput on this device. Maybe this is as good as we can get?
Presumably this could be fixed in the most radical fashion by supporting UTF-8 as a native data type.