Open XantreDev opened 1 year ago
Thank you for this bug report.
It is an interesting case. In the first iterations of the loop, the situation is like this: you have an element at index 1,666,535 and are adding an element at a small index around 0. Hermes detects this as a sparse array (because there is a lot of distance between 1,666,535 and the start of the array) and adds the element as an object property instead of an indexed array element, in order to conserve memory. At a certain point it runs out of property storage space.
This must be fixed but we need to think what the best way is.
To further clarify the current Hermes behavior. It allows us to support cases like this, which would normally run out of memory trying to allocate many gigabytes of data:
a = [1];
a[4294967294] = 1;
Thank you for this bug report.
It is an interesting case. In the first iterations of the loop, the situation is like this: you have an element at index 1,666,535 and are adding an element at a small index around 0. Hermes detects this as a sparse array (because there is a lot of distance between 1,666,535 and the start of the array) and adds the element as an object property instead of an indexed array element, in order to conserve memory. At a certain point it runs out of property storage space.
This must be fixed but we need to think what the best way is.
I think a good way to determine it: is check at some amount of elements, that each of them is number (in case of array) and allocate memory for that array
Any solution ?
Patched with
var output = (new Array(6666145 >> 2))).fill(0)
Patched with
var output = (new Array(6666145 >> 2))).fill(0)
It works!!! Thanks
Remendado com
var output = (new Array(6666145 >> 2))).fill(0)
Funciona!!! Obrigado
In which file do I put this code?
These 4 lines
var output = []
output[(input.length >> 2) - 1] = undefined
for (i = 0; i < output.length; i += 1) {
output[i] = 0
}
https://github.com/blueimp/JavaScript-MD5/blob/2c00da944e9f9ecc2348cf9ed26cd3808106aee2/js/md5.js#L256-L260 To this one
var output = (new Array(6666145 >> 2))).fill(0)
FWIW, we have a plan for fixing this. But everyone, please keep in mind that creating and using sparse arrays is almost never a good idea
FWIW, we have a plan for fixing this. But everyone, please keep in mind that creating and using sparse arrays is almost never a good idea
(new Array(6666145 >> 2))).fill(0)
still creates a holley array, is not it?
What is the most optimal way to create and fill arrays in js?
(new Array(6666145 >> 2)).fill(0)
creates a dense array. It is pretty efficient.
i have same issue using hemes with "react-native": "0.74.2"
and "expo": "~51.0.14"
Bug Description
I've used
@react-three/fiber
and tried to load GLTF model withuseGLTF
hook (it usesexpo-asset
which usesblueimp-md5
which throws with hermes).Error log:
This is the function: https://github.com/blueimp/JavaScript-MD5/blob/2c00da944e9f9ecc2348cf9ed26cd3808106aee2/js/md5.js#L257C48-L257C48 It fills array in unfamiliar way, that it not throws with small inputs, but throws with big ones
gradle clean
and confirmed this bug does not occur with JSCHermes version: React Native version (if any): 0.71.7 OS version (if any): Android Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8a / x86_64
Steps To Reproduce
Run this code inside hermes
The Expected Behavior
To not recognize array as object and not throw
The Current Behavior
Trying to use array indices as object keys and throws