Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
jonahs feedback - faster smaller messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Jul 27, 2022
1 parent dece935 commit ac5c3e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
40 changes: 21 additions & 19 deletions lib/ui/window/platform_message_response_dart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,28 @@ PlatformMessageResponseDart::~PlatformMessageResponseDart() {
}

void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> data) {
PostCompletion(std::move(callback_), ui_task_runner_, &is_complete_, channel_,
[data = std::move(data)]() mutable {
void* mapping = data->GetMutableMapping();
Dart_Handle byte_buffer;
if (mapping) {
size_t data_size = data->GetSize();
byte_buffer = Dart_NewExternalTypedDataWithFinalizer(
/*type=*/Dart_TypedData_kByteData,
/*data=*/mapping,
/*length=*/data_size,
/*peer=*/data.release(),
/*external_allocation_size=*/data_size,
/*callback=*/MappingFinalizer);
PostCompletion(
std::move(callback_), ui_task_runner_, &is_complete_, channel_,
[data = std::move(data)]() mutable {
void* mapping = data->GetMutableMapping();
Dart_Handle byte_buffer;
size_t data_size = data->GetSize();
if (mapping &&
data_size >= tonic::DartByteData::kExternalSizeThreshold) {
byte_buffer = Dart_NewExternalTypedDataWithFinalizer(
/*type=*/Dart_TypedData_kByteData,
/*data=*/mapping,
/*length=*/data_size,
/*peer=*/data.release(),
/*external_allocation_size=*/data_size,
/*callback=*/MappingFinalizer);

} else {
byte_buffer = tonic::DartByteData::Create(
data->GetMapping(), data->GetSize());
}
return byte_buffer;
});
} else {
byte_buffer =
tonic::DartByteData::Create(data->GetMapping(), data->GetSize());
}
return byte_buffer;
});
}

void PlatformMessageResponseDart::CompleteEmpty() {
Expand Down
10 changes: 4 additions & 6 deletions third_party/tonic/typed_data/dart_byte_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
namespace tonic {

namespace {

// For large objects it is more efficient to use an external typed data object
// with a buffer allocated outside the Dart heap.
const int kExternalSizeThreshold = 1000;

void FreeFinalizer(void* isolate_callback_data, void* peer) {
free(peer);
}

} // anonymous namespace

// For large objects it is more efficient to use an external typed data object
// with a buffer allocated outside the Dart heap.
const size_t DartByteData::kExternalSizeThreshold = 1000;

Dart_Handle DartByteData::Create(const void* data, size_t length) {
if (length < kExternalSizeThreshold) {
auto handle = DartByteData{data, length}.dart_handle();
Expand Down
1 change: 1 addition & 0 deletions third_party/tonic/typed_data/dart_byte_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace tonic {

class DartByteData {
public:
static const size_t kExternalSizeThreshold;
static Dart_Handle Create(const void* data, size_t length);

explicit DartByteData(Dart_Handle list);
Expand Down

0 comments on commit ac5c3e7

Please sign in to comment.