foliojs / brotli.js

A JavaScript port of the Brotli compression algorithm, as used in WOFF2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array buffer allocation failed

miherlosev opened this issue · comments

I get the error Array buffer allocation failed on machine that used for continious integration.
Machine parameters: Windows10, 1GB, 1 CPU.

I reseached code and found the strange code in build/encode.js:

for (var I, P, J, ta, K, ua, L, N, va = 0, B = 0, wa = 0, z = 0, xa = 0, ya = 0, C = 0, za = b.TOTAL_STACK || 5242880, D = b.TOTAL_MEMORY || 318767104, R = 65536; R < D || R < 2 * za; )
	R = 16777216 > R ? 2 * R : R + 16777216;
R !== D && (D = R);
assert("undefined" !== typeof Int32Array && "undefined" !== typeof Float64Array && !!(new Int32Array(1)).subarray && !!(new Int32Array(1)).set, "JS engine does not provide full typed array support");
var buffer;
buffer = new ArrayBuffer(D); //D equals 318767104 - 304 * 1024 * 1024
...

Why does your module allocate in loop 304 Mb?
It is very strange because V8 has limit 512 Mb for x86.

From what I see, the source is the constant TOTAL_MEMORY=318767104 in the Makefile in the root of https://github.com/foliojs/brotli.js that uses emcc to port https://github.com/google/brotli to the build/encode.js

For serverless solutions this proves an issue as well