diff --git a/CHANGELOG.md b/CHANGELOG.md index 74dc8c0846..e81a6edd71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Add `SentryAssetBundle` for automatic spans for asset loading (#685) * Feat: Configure idle transaction duration (#705) * Fix: `maxRequestBodySize` should be `never` by default when using the FailedRequestClientAdapter directly (#701) +* Enhancement: Use compute to offload heavy work from the main thread (#) # 6.3.0-beta.2 @@ -12,7 +13,7 @@ # 6.3.0-beta.1 -* Enha: Replace flutter default root name '/' with 'root' (#678) +* Enhancement: Replace flutter default root name '/' with 'root' (#678) * Fix: Use 'navigation' instead of 'ui.load' for auto transaction operation (#675) * Fix: Use correct data/extras type in tracer (#693) * Fix: Do not throw when Throwable type is not supported for associating errors to a transaction (#692) diff --git a/flutter/lib/src/file_system_transport.dart b/flutter/lib/src/file_system_transport.dart index 9b1e580203..f5d4bb1a0d 100644 --- a/flutter/lib/src/file_system_transport.dart +++ b/flutter/lib/src/file_system_transport.dart @@ -1,5 +1,6 @@ import 'dart:typed_data'; +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:sentry/sentry.dart'; @@ -11,12 +12,14 @@ class FileSystemTransport implements Transport { @override Future send(SentryEnvelope envelope) async { - final envelopeData = []; - await envelope.envelopeStream(_options).forEach(envelopeData.addAll); - // https://flutter.dev/docs/development/platform-integration/platform-channels#codec - final args = [Uint8List.fromList(envelopeData)]; + final eventIdLabel = envelope.header.eventId?.toString() ?? ''; + final args = await compute( + _convert, + _CaptureEnvelopeData(envelope, _options), + debugLabel: 'captureEnvelope $eventIdLabel', + ); try { - await _channel.invokeMethod('captureEnvelope', args); + await _channel.invokeMethod('captureEnvelope', [args]); } catch (exception, stackTrace) { _options.logger( SentryLevel.error, @@ -30,3 +33,19 @@ class FileSystemTransport implements Transport { return envelope.header.eventId; } } + +class _CaptureEnvelopeData { + SentryEnvelope envelope; + SentryOptions options; + + _CaptureEnvelopeData(this.envelope, this.options); +} + +Future _convert( + _CaptureEnvelopeData data, +) async { + final envelopeData = []; + await data.envelope.envelopeStream(data.options).forEach(envelopeData.addAll); + // https://flutter.dev/docs/development/platform-integration/platform-channels#codec + return Uint8List.fromList(envelopeData); +}