3

In an attempt to parallelize treatment on large TypedArrays, I tried to use the mozilla extension named SharedArrayBuffer.

These objects allow concurrent workers (or main thread) to handle the same memory (which is not made unavailable to caller of postMessage).

Unfortunately, it appears I can't read the memory of those objects I can't use DataViews on them.

I tried the following with DataViews to avoid entire buffer copies:

var arrayBuffer = new SharedArrayBuffer(4); // 4 bytes
var dataView = new DataView(new SharedArrayBuffer(4)); // fails with error below
// some usage here
var first = dataView.getFloat32(0)

which fails with the error:

TypeError: DataView: expected ArrayBuffer, got SharedArrayBuffer

I could read the memory by making a TypedArray back from the buffer, but this would clone the memory, and therefore ruin the performance gain of sharing memory as it appears to have a small overhead, such as suggested by this bug answer but then I have to know the type in advance.

Is there any solution to this?

5
  • 2
    Lars Hansen’s response at bugzilla.mozilla.org/show_bug.cgi?id=1246597#c3 seems useful for posting as an answer or update/edit to this question. Commented May 25, 2016 at 7:42
  • fixed question. I tested that new Float32Array() has indeed a negligeable overhead Commented May 25, 2016 at 9:02
  • 1
    bug is fixed in firefox 53 : bugzilla.mozilla.org/show_bug.cgi?id=1246597 Commented Mar 6, 2017 at 13:23
  • @RegisPortalez After a year... wow! Commented Sep 26, 2017 at 12:17
  • Note that SharedArrayBuffer was disabled by default in all major browsers on 5 January, 2018 in response to Spectre. Commented Jan 31, 2018 at 3:19

1 Answer 1

3

I believe the answer is no, at least for now.

There's a related bug on Bugzilla:

The SharedArrayBuffer spec says that DataView is allowed on SharedArrayBuffer, and that SharedArrayBuffer.isView() on a DataView should return true. Neither is the case in Firefox at the moment.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.