Skip to content

Commit 60ee0dd

Browse files
authored
Turbopack: reduce temp allocation during compute_blocks (#81459)
### What? Reduce allocation size a little bit.
1 parent aa9c6d2 commit 60ee0dd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

turbopack/crates/turbo-persistence/src/static_sorted_file_builder.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a> StaticSortedFileBuilder<'a> {
237237
// Last block is Index block
238238

239239
// Store the locations of the values
240-
let mut value_locations: Vec<(usize, usize)> = Vec::with_capacity(entries.len());
240+
let mut value_locations: Vec<(u16, u32)> = Vec::with_capacity(entries.len());
241241

242242
// Split the values into blocks
243243
let mut current_block_start = 0;
@@ -249,7 +249,7 @@ impl<'a> StaticSortedFileBuilder<'a> {
249249
if current_block_size + value.len() > MAX_SMALL_VALUE_BLOCK_SIZE
250250
|| current_block_count + 1 >= MAX_SMALL_VALUE_BLOCK_ENTRIES
251251
{
252-
let block_index = self.blocks.len();
252+
let block_index = self.blocks.len().try_into().unwrap();
253253
let mut block = Vec::with_capacity(current_block_size);
254254
for j in current_block_start..i {
255255
if let EntryValue::Small { value } = &entries[j].value() {
@@ -262,12 +262,13 @@ impl<'a> StaticSortedFileBuilder<'a> {
262262
current_block_size = 0;
263263
current_block_count = 0;
264264
}
265-
value_locations.push((0, current_block_size));
265+
value_locations.push((0, current_block_size.try_into().unwrap()));
266266
current_block_size += value.len();
267267
current_block_count += 1;
268268
}
269269
EntryValue::Medium { value } => {
270-
value_locations.push((self.blocks.len(), value.len()));
270+
let block_index = self.blocks.len().try_into().unwrap();
271+
value_locations.push((block_index, 0));
271272
self.blocks.push(self.compress_value_block(value));
272273
}
273274
_ => {
@@ -276,7 +277,7 @@ impl<'a> StaticSortedFileBuilder<'a> {
276277
}
277278
}
278279
if current_block_count > 0 {
279-
let block_index = self.blocks.len();
280+
let block_index = self.blocks.len().try_into().unwrap();
280281
let mut block = Vec::with_capacity(current_block_size);
281282
for j in current_block_start..entries.len() {
282283
if let EntryValue::Small { value } = &entries[j].value() {
@@ -292,20 +293,20 @@ impl<'a> StaticSortedFileBuilder<'a> {
292293
// Split the keys into blocks
293294
fn add_entry_to_block<E: Entry>(
294295
entry: &E,
295-
value_location: &(usize, usize),
296+
value_location: &(u16, u32),
296297
block: &mut KeyBlockBuilder,
297298
) {
298299
match entry.value() {
299300
EntryValue::Small { value } => {
300301
block.put_small(
301302
entry,
302-
value_location.0.try_into().unwrap(),
303-
value_location.1.try_into().unwrap(),
303+
value_location.0,
304+
value_location.1,
304305
value.len().try_into().unwrap(),
305306
);
306307
}
307308
EntryValue::Medium { .. } => {
308-
block.put_medium(entry, value_location.0.try_into().unwrap());
309+
block.put_medium(entry, value_location.0);
309310
}
310311
EntryValue::Large { blob } => {
311312
block.put_blob(entry, blob);

0 commit comments

Comments
 (0)