Closed Bug 1703505 Opened 3 years ago Closed 3 years ago

Flip pref for large arraybuffers

Categories

(Core :: JavaScript Engine, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
89 Branch
Tracking Status
firefox89 --- fixed

People

(Reporter: lth, Assigned: lth)

References

Details

(Keywords: dev-doc-complete)

Attachments

(1 file)

Currently, buffers > 2GB are off by default. We want to flip it to on by default, but to keep it for one release cycle in case something bad happens.

Blocks: 1703508
See Also: → 1691886

Do the minimal amount of work to flip the default sense of the pref
from false to true.

One test case had to be tweaked because it assumed a 2GB max and we
had not stressed this with the --large-arraybuffer switch.

Added a test for the --no-large-arraybuffer switch.

Pushed by lhansen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/2a0b482df566
Flip pref for large ArrayBuffer. r=jandem
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 89 Branch
See Also: → 1706772

Hi Lars, I'm documenting this for FF89.

I did a test on Firefox 88 using new ArrayBuffer(Math.pow(2, 31)) (=2GB) which failed and new ArrayBuffer(Math.pow(2, 31) - 1) which succeeded. I then tested on FF89 and played with the preference to verify that new ArrayBuffer(Math.pow(2, 32)) and new ArrayBuffer(Math.pow(2, 33)) work, but that new ArrayBuffer(Math.pow(2, 34)) failed. From this I can see that the pref does indeed allow > 2GB values.

  1. Can we canonically say how big the values are that are allowed? Or is this based on available memory for the browser or something else?

Further, I looked at the docs on invalid array length, which indicate that

  • the array size is implemented as a 32 bit unsigned integer.
  • there is an error if the array is negative or if the size is greater than (2^32)-1 . This being because the array size is implemented as a NOTE though, that (2^32) is 4GB!
  1. So above confuses me because (2^32)-1 is greater than 2GB, and indeed if you try it it fails in FF88. My assumption then is that invalid array length is incorrect and there is something else setting the limit - ie maybe it isn't a 32 bit integer.
    Can you comment on the inconsistency?
Flags: needinfo?(lhansen)

At the moment, we limit the ArrayBuffer to 8GB on 64-bit systems, but this is a little arbitrary. Most likely, larger buffers will be allowed in the future. It would be good to document that there is an internal maximum but not specifically what the maximum is, probably.

On 32-bit systems, the max remains 2GB-1 and we're unlikely ever to increase that, given that 32-bit systems are becoming less relevant.

The current documentation for invalid array length looks like it was previously wrong for ArrayBuffer, in particular new ArrayBuffer(Math.pow(2, 32) - 1) should fail in FF88 on all platforms. I believe that currently (FF89 and later):

  • for Array, the max length is 2^32-1 (largest unsigned 32-bit integer), since an error is thrown for 2^32 but not for 2^32-1
  • for ArrayBuffer, the current max is 2^33 [sic] on 64-bit systems (8GB) and 2^31-1 on 32-bit systems (2GB-1)

Note that Array and ArrayBuffer are independent data structures and the implementation of one has no influence on the implementation of the other.

Flags: needinfo?(lhansen)
See Also: 1706772

Thanks very much @Lars!
I have updated the docs in https://github.com/mdn/content/pull/4470. Feel free to make further comments. The main change is to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length to clarify the points you made above.

Note that I did end up mentioning the explicit size of 8GB, but I also made it clear that this is for 64bit OS on FF89 and later.

(In reply to Hamish Willee from comment #6)

Thanks very much @Lars!
I have updated the docs in https://github.com/mdn/content/pull/4470. Feel free to make further comments. The main change is to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length to clarify the points you made above.

Note that I did end up mentioning the explicit size of 8GB, but I also made it clear that this is for 64bit OS on FF89 and later.

Left a comment about a typo, otherwise looked OK to me.

Docs completed by Hamish in https://github.com/mdn/content/issues/4314, so marking this as DDC.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: