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

Enhancement: Use compute to offload heavy work from the main thread #707

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
29 changes: 24 additions & 5 deletions flutter/lib/src/file_system_transport.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:sentry/sentry.dart';

Expand All @@ -11,12 +12,14 @@ class FileSystemTransport implements Transport {

@override
Future<SentryId?> send(SentryEnvelope envelope) async {
final envelopeData = <int>[];
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<void>('captureEnvelope', args);
await _channel.invokeMethod<void>('captureEnvelope', [args]);
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
Expand All @@ -30,3 +33,19 @@ class FileSystemTransport implements Transport {
return envelope.header.eventId;
}
}

class _CaptureEnvelopeData {
SentryEnvelope envelope;
SentryOptions options;

_CaptureEnvelopeData(this.envelope, this.options);
}

Future<Uint8List> _convert(
_CaptureEnvelopeData data,
) async {
final envelopeData = <int>[];
await data.envelope.envelopeStream(data.options).forEach(envelopeData.addAll);
// https://flutter.dev/docs/development/platform-integration/platform-channels#codec
return Uint8List.fromList(envelopeData);
}