Closed Bug 939439 Opened 12 years ago Closed 3 years ago

Creating Blob from Uint8Array doubles memory use

Categories

(Core :: JavaScript Engine, enhancement)

25 Branch
x86_64
Linux
enhancement
Not set
normal

Tracking

()

RESOLVED INACTIVE

People

(Reporter: nicolas.george, Unassigned)

Details

Using the following minimal HTML file: <script> var test_array; var test_blob; function create_array() { test_array = new Uint8Array(512 * 1024 * 1024); for (var i = 0; i < test_array.length; i++) test_array[i] = i; alert("array created, length = " + test_array.length); } function create_blob() { test_blob = Blob([ test_array ], { type: "application/octet-stream" }); alert("blob created, size = " + test_blob.size); } </script> <p onclick="create_array()">create array</p> <p onclick="create_blob()">create blob</p> Observe (using ps) memory use before and after creating the array and the blob. Result: Before: VSZ = 295476 / RSS = 75544 After create array: VSZ = 838292 RSS = 601180 (+ ~513 M) After create blob: VSZ = 1362588 RSS = 1122992 (+ ~510 M) Memory increase after create array is normal. When creating the Blob, sharing the memory buffers (using some kind of copy-on-write) should allow to avoid the increase of memory use. Since the L in "blob" usually means "large", it can be a real issue. The problem was initially spotted when using a blob to download, decrypt and offer to save a 500 M file and the array → blob step caused an out-of-memory condition in the browser.
> sharing the memory buffers (using some kind of copy-on-write) Would mean that all writes to typed arrays end up getting slower, generally... :(
Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → INACTIVE
You need to log in before you can comment on or make changes to this bug.