@@ -22,13 +22,19 @@ use crate::{
2222 raw_transfer_types:: { EcmaScriptModule , Error , RawTransferData } ,
2323} ;
2424
25- // For raw transfer, use a buffer 4 GiB in size, with 4 GiB alignment.
25+ // For raw transfer, use a buffer 2 GiB in size, with 4 GiB alignment.
2626// This ensures that all 64-bit pointers have the same value in upper 32 bits,
2727// so JS only needs to read the lower 32 bits to get an offset into the buffer.
28- // However, only use first half of buffer (2 GiB) for the arena, so 32-bit offsets
29- // don't have the highest bit set. JS bitwise operators interpret the highest bit as sign bit,
30- // so this enables using `>>` bitshift operator in JS, rather than the more expensive `>>>`,
31- // without offsets being interpreted as negative.
28+ //
29+ // Buffer size only 2 GiB so 32-bit offsets don't have the highest bit set.
30+ // This is advantageous for 2 reasons:
31+ //
32+ // 1. V8 stores small integers ("SMI"s) inline, rather than on heap, which is more performant.
33+ // But when V8 pointer compression is enabled, 31 bits is the max integer considered an SMI.
34+ // So using 32 bits for offsets would be a large perf hit when pointer compression is enabled.
35+ // 2. JS bitwise operators work only on signed 32-bit integers, with 32nd bit as sign bit.
36+ // So avoiding the 32nd bit being set enables using `>>` bitshift operator, which may be cheaper
37+ // than `>>>`, without offsets being interpreted as negative.
3238const TWO_GIB : usize = 1 << 31 ;
3339const FOUR_GIB : usize = 1 << 32 ;
3440
0 commit comments