This commit is contained in:
Jordi Baylina
2020-10-06 20:35:30 +02:00
parent 3772e990ef
commit 70c80b7cb6
3 changed files with 8 additions and 3 deletions

View File

@@ -63,6 +63,7 @@ export default class PolField {
}
_setRoots(n) {
if (n > this.F.sqrt_s) n = this.s;
for (let i=n; (i>=0) && (!this.roots[i]); i--) {
let r = this.F.one;
const nroots = 1 << i;

View File

@@ -18,7 +18,8 @@
along with wasmsnark. If not, see <https://www.gnu.org/licenses/>.
*/
const MEM_SIZE = 1000; // Memory size in 64K Pakes (512Mb)
// const MEM_SIZE = 1000; // Memory size in 64K Pakes (512Mb)
const MEM_SIZE = 25; // Memory size in 64K Pakes (1600Kb)
import thread from "./threadman_thread.js";
@@ -111,6 +112,8 @@ export default async function buildThreadManager(wasm, singleThread) {
} else {
concurrency = os.cpus().length;
}
// Limit to 64 threads for memory reasons.
if (concurrency>64) concurrency=64;
tm.concurrency = concurrency;
for (let i = 0; i<concurrency; i++) {

View File

@@ -1,6 +1,7 @@
/* global WebAssembly */
export default function thread(self) {
const MAXMEM = 32767;
let instance;
let memory;
@@ -29,7 +30,7 @@ export default function thread(self) {
async function init(data) {
const code = new Uint8Array(data.code);
const wasmModule = await WebAssembly.compile(code);
memory = new WebAssembly.Memory({initial:data.init, maximum: 32767});
memory = new WebAssembly.Memory({initial:data.init, maximum: MAXMEM});
instance = await WebAssembly.instantiate(wasmModule, {
env: {
@@ -48,7 +49,7 @@ export default function thread(self) {
if (u32[0] + length > memory.buffer.byteLength) {
const currentPages = memory.buffer.byteLength / 0x10000;
let requiredPages = Math.floor((u32[0] + length) / 0x10000)+1;
if (requiredPages>32767) requiredPages=32767;
if (requiredPages>MAXMEM) requiredPages=MAXMEM;
memory.grow(requiredPages-currentPages);
}
return res;