diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2020-03-01 17:17:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-01 17:17:59 -0500 |
commit | ad21210edd5aabdeebe70809672b4224cc6f41c9 (patch) | |
tree | df6e499a4c3adde676cf029b13cbcc03a2720924 /core/shared_queue.js | |
parent | c3661e9f0731c8e6d2952de23eaeaaa1dc6ca4da (diff) |
perf: use subarray instead of slice in dispatch minimal (#4180)
Diffstat (limited to 'core/shared_queue.js')
-rw-r--r-- | core/shared_queue.js | 9 |
1 files changed, 6 insertions, 3 deletions
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; } |