New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 687238 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Nov 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Create WTF::Vector from existing allocated memory

Project Member Reported by dougt@chromium.org, Jan 31 2017

Issue description

It would be nice if we could avoid a copy when creating WTF::Vector.

Given a |blink::DOMArrayPiece value|, we would like to convert to a Vector<uint8_t> such that copies can be avoided.

For example:

  blink::DOMArrayPiece value;  // allocated / assigned somewhere


  Vector<uint8_t> valueVector;
  valueVector.append(value.bytes(), value.byteLength());


This code exists today here:

https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp?q=valueVector.append+package:%5Echromium$&l=207


 

Comment 1 by dougt@chromium.org, Jan 31 2017

Components: -Infra>Client>V8 Blink>Internals>WTF

Comment 2 by dcheng@chromium.org, Jan 31 2017

Do we need this generally throughout Blink, or is this just for Mojo interop?

Comment 3 by dougt@chromium.org, Jan 31 2017

If you expose a new feature to the web that accepts a BufferSource [1], the C++ binding for this sort of thing will be a blink::DOMArrayPiece. Depending on what you're going to do, you will probably need to pass that object over mojo.  So, it could be fixed with a way to serialize the DOMArrayPiece (without a copy if possible).  WDYT?

[1]https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.idl

Comment 4 by yutak@chromium.org, Jan 31 2017

Cc: yutak@chromium.org
There are some complexities, and I'm not sure even whether this is doable.

* Our allocator distinguishes backing buffer for containers from regular
  allocations; also Oilpan allocations are totally different
* Expansion/shrinking? Realloc?

Why do you need to use Vector here? If you don't expand/shrink/update elements,
(theoretically) you don't have to use Vectors, since a raw pointer to the backing
buffer should be usually sufficient.

Comment 5 by dcheng@chromium.org, Jan 31 2017

Components: Internals>Mojo>Bindings
It sounds like we really just need Mojo support here. If we could typemap DOMArrayPiece to array<uint8_t>, I think that would solve this problem.

Comment 6 by sa...@chromium.org, Jan 31 2017

Cc: sa...@chromium.org
There are two problems with typemapping DOMArrayPiece to array<uint8_t>:
1. Typemaps map from a mojo type to a C++ type, so array<uint8_t> couldn't map to both WTF::Vector<uint8_t> and WTF::ArrayPiece at the same time.
2. Typemaps only map structs, unions and enums.

What is possible today is wrapping the array in a mojom struct:
struct Uint8ArrayWrapper {
  array<uint8> data;
};
typemapping that to a C++ struct:
struct Uint8ArrayWrapper {
  ArrayPiece* data;
};
with traits:
struct StructTraits<blink::mojom::Uint8ArrayWrapperDataView, blink::Uint8ArrayWrapper> {
  ConstCArray data(const Uint8ArrayWrapper& wrapper) {
    return ConstCArray(wrapper.data.byteLength(), wrapper.data.bytes());
}

This has some problems. Uint8ArrayWrapper is not reasonably receivable in the blink variant; StructTraits that create an ArrayPiece seems pretty terrible. Further, it's another wrapper.

Fixing this nicely probably requires decoupling the send and receive interfaces. That is, the send interface could accept anything that looks like an array (via ArrayTraits), but the receive side probably just wants a vector.

Comment 7 by sa...@chromium.org, Jan 31 2017

Cc: tibell@chromium.org
Status: WontFix (was: Untriaged)
No action in close to 12 months, closing as obsolete.

Please re-open if you think it's still valid.

Sign in to add a comment