NetLogo / Tortoise

Compiler and runtime engine for NetLogo models that runs in JavaScript 🐢
https://netlogoweb.org
Other
56 stars 27 forks source link

Encode Encore: bytes-to-base64 not working when the input is too large #233

Closed CIVITAS-John closed 2 years ago

CIVITAS-John commented 2 years ago

Please refer to the second answer: the current way to implement the function is

btoa(String.fromCharCode(bytes...))

However, when the length of bytes gets too large, it will exceed the call stack limit. Therefore, seems that the first answer provides a better way to implement, and we could fix this issue very easily.

CIVITAS-John commented 2 years ago

Also, I am not sure if the functional style in this extension could bring up the best performance. We don't need to call a function for each byte.

CIVITAS-John commented 2 years ago

A very quick change in the compiled js file:

 for (var x of bytes) {
  if (!(checks.isNumber(x) && (x >= 0) && (x <= 255)))
    throw exceptions.extension(`All elements of the list argument to 'encode:${primName}' must be numbers between 0 and 255`);
}
return f(bytes);
TheBizzle commented 2 years ago

What are the "first answer" and "second answer" that you're referring to?

CIVITAS-John commented 2 years ago

This is how we implemented: image

This is the better (and uglier) way: image

TheBizzle commented 2 years ago

I have not been able to reproduce this issue with either a 40MB string passed to base64-to-bytes, nor with a 100MB string passed to string-to-bytes.

Please include in your report

CIVITAS-John commented 2 years ago

Hi, the primitive you need to test is bytes-to-base64, not vice versa.

Please also consider changing the verification to a simple loop (instead of nested functions).

CIVITAS-John commented 2 years ago

The easiest way is just to convert your 40MB string to bytes and back to base64.