From ad21210edd5aabdeebe70809672b4224cc6f41c9 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 1 Mar 2020 17:17:59 -0500 Subject: perf: use subarray instead of slice in dispatch minimal (#4180) --- core/shared_queue.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'core/shared_queue.js') diff --git a/core/shared_queue.js b/core/shared_queue.js index 093cc223f..742a90995 100644 --- a/core/shared_queue.js +++ b/core/shared_queue.js @@ -115,7 +115,8 @@ SharedQueue Binary Layout if (index == 0) { return HEAD_INIT; } else { - return shared32[INDEX_OFFSETS + 2 * (index - 1)]; + const prevEnd = shared32[INDEX_OFFSETS + 2 * (index - 1)]; + return (prevEnd + 3) & ~3; } } else { return null; @@ -125,16 +126,18 @@ SharedQueue Binary Layout function push(opId, buf) { const off = head(); const end = off + buf.byteLength; + const alignedEnd = (end + 3) & ~3; const index = numRecords(); - if (end > shared32.byteLength || index >= MAX_RECORDS) { + if (alignedEnd > shared32.byteLength || index >= MAX_RECORDS) { // console.log("shared_queue.js push fail"); return false; } setMeta(index, end, opId); + assert(alignedEnd % 4 === 0); assert(end - off == buf.byteLength); sharedBytes.set(buf, off); shared32[INDEX_NUM_RECORDS] += 1; - shared32[INDEX_HEAD] = end; + shared32[INDEX_HEAD] = alignedEnd; return true; } -- cgit v1.2.3