Skip to content

Commit cc1e9fc

Browse files
committed
perf(napi/parser): raw transfer: reduce size of buffer by 16 bytes (#12277)
Reduce the size of the buffer used for raw transfer by 16 bytes so that there's 16 bytes space for `malloc`'s metadata without committing another memory page. I don't know for sure that `malloc` would store metadata in the allocation for allocations this large, but this is what Bumpalo does, so it's probably a good idea.
1 parent 5fba91c commit cc1e9fc

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

crates/oxc_allocator/src/generated/fixed_size_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
#![expect(clippy::unreadable_literal)]
55

6-
pub const BUFFER_SIZE: usize = 2147483648;
6+
pub const BUFFER_SIZE: usize = 2147483632;
77
pub const BUFFER_ALIGN: usize = 4294967296;

napi/parser/generated/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Auto-generated code, DO NOT EDIT DIRECTLY!
22
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.
33

4-
const BUFFER_SIZE = 2147483648,
4+
const BUFFER_SIZE = 2147483632,
55
BUFFER_ALIGN = 4294967296,
6-
DATA_POINTER_POS_32 = 536870910,
7-
IS_TS_FLAG_POS = 2147483644,
6+
DATA_POINTER_POS_32 = 536870906,
7+
IS_TS_FLAG_POS = 2147483628,
88
PROGRAM_OFFSET = 0;
99

1010
module.exports = {

napi/parser/generated/deserialize/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function deserialize(buffer, sourceTextInput, sourceLenInput) {
2020
sourceLen = sourceLenInput;
2121
sourceIsAscii = sourceText.length === sourceLen;
2222

23-
const data = deserializeRawTransferData(uint32[536870910]);
23+
const data = deserializeRawTransferData(uint32[536870906]);
2424

2525
uint8 =
2626
uint32 =

napi/parser/generated/deserialize/ts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function deserialize(buffer, sourceTextInput, sourceLenInput) {
2020
sourceLen = sourceLenInput;
2121
sourceIsAscii = sourceText.length === sourceLen;
2222

23-
const data = deserializeRawTransferData(uint32[536870910]);
23+
const data = deserializeRawTransferData(uint32[536870906]);
2424

2525
uint8 =
2626
uint32 =

napi/parser/src/generated/raw_transfer_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
#![expect(clippy::unreadable_literal)]
55

6-
pub const BUFFER_SIZE: usize = 2147483648;
6+
pub const BUFFER_SIZE: usize = 2147483632;
77
pub const BUFFER_ALIGN: usize = 4294967296;

tasks/ast_tools/src/generators/raw_transfer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use super::define_generator;
2828

2929
/// Size of raw transfer buffer.
3030
/// Must be a multiple of 16.
31-
const BUFFER_SIZE: u32 = 1 << 31; // 2 GiB
31+
/// 16 bytes less than 2 GiB, to allow 16 bytes for `malloc` metadata (like Bumpalo does).
32+
const BUFFER_SIZE: u32 = (1 << 31) - 16; // 2 GiB - 16 bytes
3233
const _: () = assert!(BUFFER_SIZE % 16 == 0);
3334
/// Alignment of raw transfer buffer.
3435
const BUFFER_ALIGN: u64 = 1 << 32; // 4 GiB

0 commit comments

Comments
 (0)