Skip to content

Find a way to do less copying when sending large typed data #34796

Closed
@alexmarkov

Description

@alexmarkov

When sending a large typed data through a message port, there is an optimization to convert it to an external typed data (

if ((kind == Snapshot::kMessage) &&
(bytes >= kExternalizeTypedDataThreshold)) {
// Write as external.
writer->WriteIndexedObject(external_cid);
writer->WriteTags(writer->GetObjectTags(this));
writer->Write<RawObject*>(ptr()->length_);
uint8_t* data = reinterpret_cast<uint8_t*>(ptr()->data());
void* passed_data = malloc(bytes);
if (passed_data == NULL) {
OUT_OF_MEMORY();
}
memmove(passed_data, data, bytes);
static_cast<MessageWriter*>(writer)->finalizable_data()->Put(
bytes,
passed_data, // data
passed_data, // peer,
IsolateMessageTypedDataFinalizer);
) to avoid copying on the receiver side. This morphs object from one type to another, which causes problems flutter/flutter#22796, #34752.

As a workaround to these problems, the optimization of converting typed data to external will be put under a flag and disabled by default. However, we still need to find a way to do less copying when sending large amount of data through message ports, preferably without morphing object types.

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions