Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export async function createHotReloaderTurbopack(
}
)
backgroundLogCompilationEvents(project, {
eventTypes: ['StartupCacheInvalidationEvent'],
eventTypes: ['StartupCacheInvalidationEvent', 'TimingEvent'],
})
setBundlerFindSourceMapImplementation(
getSourceMapFromTurbopack.bind(null, project, projectPath)
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbo-persistence-tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::path::PathBuf;

use anyhow::{Context, Result, bail};
use turbo_persistence::{MetaFileEntryInfo, TurboPersistence};
use turbo_persistence::{MetaFileEntryInfo, SerialScheduler, TurboPersistence};

fn main() -> Result<()> {
// Get CLI argument
Expand All @@ -16,7 +16,7 @@ fn main() -> Result<()> {
bail!("The provided path does not exist: {}", path.display());
}

let db = TurboPersistence::open_read_only(path)?;
let db: TurboPersistence<SerialScheduler> = TurboPersistence::open_read_only(path)?;
let meta_info = db
.meta_info()
.context("Failed to retrieve meta information")?;
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbo-persistence/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ memmap2 = "0.9.5"
parking_lot = { workspace = true }
qfilter = { version = "0.2.4", features = ["serde"] }
quick_cache = { workspace = true }
rayon = { workspace = true }
rustc-hash = { workspace = true }
smallvec = { workspace = true}
thread_local = { workspace = true }
Expand All @@ -32,6 +31,7 @@ zstd = { version = "0.13.2", features = ["zdict_builder"] }

[dev-dependencies]
rand = { workspace = true, features = ["small_rng"] }
rayon = { workspace = true }
tempfile = { workspace = true }

[lints]
Expand Down
9 changes: 9 additions & 0 deletions turbopack/crates/turbo-persistence/src/collector.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem::take;

use crate::{
ValueBuffer,
collector_entry::{CollectorEntry, CollectorEntryValue, EntryKey},
Expand Down Expand Up @@ -111,4 +113,11 @@ impl<K: StoreKey, const SIZE_SHIFT: usize> Collector<K, SIZE_SHIFT> {
self.total_value_size = 0;
self.entries.drain(..)
}

/// Clears the collector and drops the capacity
pub fn drop_contents(&mut self) {
drop(take(&mut self.entries));
self.total_key_size = 0;
self.total_value_size = 0;
}
}
21 changes: 14 additions & 7 deletions turbopack/crates/turbo-persistence/src/compaction/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ impl Default for CompactConfig {
optimal_merge_count: 8,
max_merge_count: 32,
max_merge_bytes: 500 * MB,
min_merge_duplication_bytes: MB,
optimal_merge_duplication_bytes: 10 * MB,
min_merge_duplication_bytes: 50 * MB,
optimal_merge_duplication_bytes: 100 * MB,
max_merge_segment_count: 8,
}
}
Expand Down Expand Up @@ -233,13 +233,20 @@ pub fn get_merge_segments<T: Compactable>(
// We have reached the maximum number of merge jobs, so we stop here.
break;
}
let mut current_range = start_compactable.range();
let start_compactable_range = start_compactable.range();
let start_compactable_size = start_compactable.size();
let mut current_range = start_compactable_range.clone();

// We might need to restart the search if we need to extend the range.
'search: loop {
let mut current_set = smallvec![start_index];
let mut current_size = start_compactable.size();
let mut current_size = start_compactable_size;
let mut duplication = IntervalMap::<Option<DuplicationInfo>>::new();
duplication.update(start_compactable_range.clone(), |dup_info| {
dup_info
.get_or_insert_default()
.add(start_compactable_size, &start_compactable_range);
});
let mut current_skip = 0;

// We will capture compactables in the current_range until we find a optimal merge
Expand Down Expand Up @@ -609,8 +616,8 @@ mod tests {
min_merge_count: 2,
optimal_merge_count: 4,
max_merge_bytes: 5000,
min_merge_duplication_bytes: 200,
optimal_merge_duplication_bytes: 500,
min_merge_duplication_bytes: 500,
optimal_merge_duplication_bytes: 1000,
max_merge_segment_count: 4,
};
let jobs = get_merge_segments(&containers, &config);
Expand Down Expand Up @@ -653,7 +660,7 @@ mod tests {
println!("Number of compactions: {number_of_compactions}");

let metrics = compute_metrics(&containers, 0..=KEY_RANGE);
assert!(number_of_compactions < 40);
assert!(number_of_compactions < 30);
assert!(containers.len() < 30);
assert!(metrics.duplication < 0.5);
}
Expand Down
Loading