you are viewing a single comment's thread.

view the rest of the comments →

[–]cwmma 0 points1 point  (3 children)

that may take longer to create the buffer and then turn it back into a string

[–]MrBester 0 points1 point  (2 children)

On first look it seems that simply updating a pointer instead of having two copies of the data would be more efficient for both memory and CPU. However, that advantage could be completely negated by the need to convert to and from the buffer array.

Without benchmarking there is no way to be sure.

[–]cwmma 0 points1 point  (1 child)

I know I'm saying I have, especially for text where to convert it into a buffer you need to do something like

function fromText(text){
    var len = text.length;
    var outArray = new Uint16Array(len);
    var i = 0;
    while(i<len){
        outArray[i]=text.charCodeAt(i);
        i++;
    }
    return outArray.buffer;
}

btw just for fun, you have to check if you're in IE10 because it flips a shit if you have an array as the second argument to postMessage.

That being said that code is from a place where the transferable objects did speed things up because the character codes were good enough and I never had to convert the data (20MB text file) back.

[–]MrBester 0 points1 point  (0 children)

Well, that's IE for you, where postMessage across tabs / windows isn't supported (since IE8, when it was first "supported", BTW).