emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

[file_packager] split data files when file size exceeds ArrayBuffer limit

Open arsnyder16 opened this issue 5 months ago • 9 comments

Addresses #24691

Currently [ArrayBuffer cannot be larger than 2046 on chrome. So bundling a large amount of files using file_packager.py the .data will not be allowed to load. Breaking up files into multiple data files by passes this issue.

error while handling : http://localhost:3040/Gtest.data Error: Unexpected error while handling : http://localhost:3040/Gtest.data 
RangeError: Array buffer allocation failed

arsnyder16 avatar Jul 29 '25 18:07 arsnyder16

@sbc100 Is this aligned with what you were thinking?

arsnyder16 avatar Jul 29 '25 18:07 arsnyder16

Can we add some tests for this? What are the specific limits you are running into? Are those limits not fixed? i.e. does it need to be configurable?

I wanted to make sure i was on the right track before adding tests. The limits are described in conversation in the issue i mentioned. We can hard code the limit to 2Gi as a likely guess at a true limit. If that is what you prefer its simpler from testing perspective . Seemed more flexible to make it configurable to anyone calling the utility, but i get the simplicity side of it

arsnyder16 avatar Jul 29 '25 18:07 arsnyder16

This does seem like a reasonable approach.

I'm still a little fuzzy on exactly why and when this might be needed in the real world, I think I need to go re-read our original discussion, but I also think including more information in the PR (i.e. in the description, or in comments) would be good.

sbc100 avatar Jul 29 '25 18:07 sbc100

This does seem like a reasonable approach.

I'm still a little fuzzy on exactly why and when this might be needed in the real world, I think I need to go re-read our original discussion, but I also think including more information in the PR (i.e. in the description, or in comments) would be good.

Updated the description, based on that if you want me to hard code the limit into the package i can take that approach

arsnyder16 avatar Jul 29 '25 18:07 arsnyder16

@sbc100 Going to look at adding tests for this. Do you have an recommendations? Would you like me to generate temporary files (s) so that i can reach the 2Gi limit?

arsnyder16 avatar Aug 04 '25 13:08 arsnyder16

@sbc100 This should be ready for review, not sure about the test failure if they are flaky or if its related to my change. I don't see them fail locally.

arsnyder16 avatar Aug 11 '25 12:08 arsnyder16

Peculiarly I find that in Chrome, the max ArrayBuffer limit is not 2GB (2048MB), but 2046MB:

image

Firefox supports up to 16GB ArrayBuffers:

image

In node.js I get up to 4GB ArrayBuffers:

image

What is your target environment?

juj avatar Aug 18 '25 20:08 juj

@juj Thanks! My target is chrome, i incorrectly associated in the ArrayBuffer documentation [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/ArrayBuffer#exceptions) to MAX_INT`. I didn't specifically test the exact limit, rather was just trying to follow the documentation but clearly misinterpreted it.

Looks like Chrome has the lowest limit, i will change to use that limit.

Safari appears to be 4Gi image

arsnyder16 avatar Aug 19 '25 02:08 arsnyder16

@juj @sbc100 Anything else on this?

arsnyder16 avatar Sep 17 '25 18:09 arsnyder16