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 2 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
27 changes: 23 additions & 4 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,10 +12,12 @@ 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args previously was an array

Suggested change
await _channel.invokeMethod<void>('captureEnvelope', args);
await _channel.invokeMethod<void>('captureEnvelope', [args]);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a comment which tells you which type should get passed. Probably also a test which asserts that 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's indeed another problem, but the error is actually with the compute flag, See #707 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at least the tests are now passing.

} catch (exception, stackTrace) {
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);
}