Skip to content

Commit 29beadd

Browse files
xusd320fireairforce
authored andcommitted
feat(turbopack): apply utoo patches to canary
1 parent 71228c4 commit 29beadd

93 files changed

Lines changed: 2791 additions & 583 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 115 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ napi-derive = "2"
301301
napi-build = "2"
302302
nohash-hasher = "0.2.0"
303303
notify = "8.1.0"
304+
notify-types = "2.0.0"
304305
once_cell = "1.21.3"
305306
owo-colors = "4.2.2"
306307
parcel_selectors = "0.28.2"
@@ -315,6 +316,7 @@ qstring = "0.7.2"
315316
quick_cache = { version = "0.6.14" }
316317
quote = "1.0.23"
317318
rand = "0.10.0"
319+
getrandom = "0.3"
318320
rayon = "1.10.0"
319321
regex = "1.10.6"
320322
regress = "0.10.4"
@@ -345,8 +347,8 @@ tempfile = "3.20.0"
345347
terminal_size = "0.3.0"
346348
thiserror = "1.0.48"
347349
thread_local = "1.1.8"
348-
tokio = "~1.47.3"
349-
tokio-util = { version = "0.7.13", features = ["io", "rt"] }
350+
tokio = "1.51.0"
351+
tokio-util = { version = "=0.7.16", features = ["io", "rt"] }
350352
tracing = "0.1.37"
351353
tracing-subscriber = "0.3.16"
352354
triomphe = { git = "https://github.com/sokra/triomphe", branch = "sokra/unstable" }
@@ -367,3 +369,5 @@ virtue = { git = "https://github.com/bgw/virtue.git", branch = "bgw/fix-generic-
367369
mdxjs = { git = "https://github.com/vercel-labs/mdxjs-rs-turbopack.git", branch = "turbopack" }
368370
# Doesn't compile on recent nightly versions because of https://github.com/Michael-F-Bryan/include_dir/pull/117
369371
include_dir = { git = "https://github.com/vercel-labs/include_dir", branch = "turbopack" }
372+
tokio = { git = "https://github.com/utooland/tokio.git", package = "tokio" }
373+
tokio-util = { git = "https://github.com/utooland/tokio.git", package = "tokio-util" }

turbopack/crates/turbo-persistence/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ memmap2 = "0.9.5"
2525
nohash-hasher = { workspace = true }
2626
parking_lot = { workspace = true }
2727
# See https://github.com/vercel/next.js/issues/91708 for why we need the legacy_x86_64_support feature
28-
qfilter = { version = "0.3.0-alpha.3", features = ["serde", "legacy_x86_64_support"] }
28+
qfilter = { version = "0.3.0-alpha.4", features = ["serde", "legacy_x86_64_support"] }
2929
postcard = { workspace = true, features = ["alloc", "use-std"] }
3030
zerocopy = { version = "0.8", features = ["derive"] }
3131
quick_cache = { workspace = true }

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,10 @@ impl<E: Entry> StreamingSstWriter<E> {
947947
// Hashes are already sorted by key_hash (SST invariant), but fingerprints
948948
// (truncated hashes) may not be sorted, so we sort by `fingerprint & mask`.
949949
let actual_count = self.collected_fingerprints.len() as u64;
950-
let mut builder = qfilter::Builder::new(actual_count.max(1), AMQF_FALSE_POSITIVE_RATE)
951-
.expect("Filter can't be constructed");
950+
let mut builder = qfilter::Builder::new(
951+
qfilter::Filter::new(actual_count.max(1), AMQF_FALSE_POSITIVE_RATE)
952+
.expect("Filter can't be constructed"),
953+
);
952954
let fp_size = builder.fingerprint_size();
953955
assert!(fp_size < 32, "fp_size {fp_size} exceeds u32");
954956
let fp_mask = (1u32 << fp_size) - 1;

turbopack/crates/turbo-tasks-backend/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ smallvec = { workspace = true }
5454
tokio = { workspace = true }
5555
tracing = { workspace = true }
5656
turbo-bincode = { workspace = true }
57-
turbo-persistence = { workspace = true }
5857
turbo-rcstr = { workspace = true }
5958
turbo-tasks = { workspace = true }
6059
turbo-tasks-hash = { workspace = true }
6160
thread_local = { workspace = true }
6261

62+
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
63+
turbo-persistence = { workspace = true }
64+
6365
[dev-dependencies]
6466
criterion = { workspace = true, features = ["async_tokio"] }
6567
futures = { workspace = true }

turbopack/crates/turbo-tasks-backend/src/backend/operation/aggregation_update.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
ops::{ControlFlow, Deref},
88
sync::Arc,
99
thread::yield_now,
10-
time::{Duration, Instant},
10+
time::Duration,
1111
};
1212

1313
use anyhow::Result;
@@ -16,6 +16,7 @@ use indexmap::map::Entry;
1616
use ringmap::RingSet;
1717
use rustc_hash::{FxBuildHasher, FxHashMap};
1818
use smallvec::{SmallVec, smallvec};
19+
use tokio::time::Instant;
1920
#[cfg(feature = "trace_aggregation_update_queue")]
2021
use tracing::span::Span;
2122
#[cfg(any(

turbopack/crates/turbo-tasks-backend/src/backend/operation/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,33 @@ impl<'e, B: BackingStorage> ExecuteContextImpl<'e, B> {
239239
StorageWriteGuard<'e>,
240240
),
241241
) {
242+
// Fast path: no backing storage (e.g. WASM/NoopKvDb) — process inline,
243+
// skip the Vec allocation needed for batch DB restoration.
244+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
245+
if !self.backend.should_restore() {
246+
for (id, category) in task_ids {
247+
let mut task = self.backend.storage.access_mut(id);
248+
if !task.flags.is_restored(category) {
249+
task.flags.set_restored(category);
250+
}
251+
if id.is_transient() {
252+
if call_prepared_task_callback_for_transient_tasks {
253+
prepared_task_callback(self, id, category, task);
254+
}
255+
} else {
256+
prepared_task_callback(self, id, category, task);
257+
}
258+
}
259+
return;
260+
}
242261
let span = trace_span!(
243262
"prepare_tasks_with_callback",
244263
reason,
245264
requested_data = tracing::field::Empty,
246265
requested_meta = tracing::field::Empty,
247266
);
248267
let _guard = span.enter();
268+
249269
let mut data_count = 0;
250270
let mut meta_count = 0;
251271
let mut all_count = 0;

turbopack/crates/turbo-tasks-backend/src/database/key_value_database.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::Result;
22
use smallvec::SmallVec;
3+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
34
use turbo_persistence::{FamilyConfig, FamilyKind};
45

56
use crate::database::write_batch::ConcurrentWriteBatch;
@@ -11,6 +12,8 @@ pub enum KeySpace {
1112
TaskData = 2,
1213
TaskCache = 3,
1314
}
15+
16+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
1417
impl KeySpace {
1518
/// Constructs a [`KeySpace`] from its numeric index (i.e., the `usize` discriminant).
1619
///

turbopack/crates/turbo-tasks-backend/src/database/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ pub mod db_invalidation;
22
pub mod db_versioning;
33
pub mod key_value_database;
44
pub mod noop_kv;
5+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
56
pub mod turbo;
67
pub mod write_batch;

turbopack/crates/turbo-tasks-backend/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ mod utils;
1212
use std::path::Path;
1313

1414
use anyhow::Result;
15+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
1516
use turbo_persistence::{CompactConfig, TurboPersistence};
1617

17-
use crate::database::{
18-
noop_kv::NoopKvDb,
19-
turbo::{self, TurboKeyValueDatabase},
20-
};
18+
use crate::database::noop_kv::NoopKvDb;
19+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
20+
use crate::database::turbo::TurboKeyValueDatabase;
21+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
22+
use crate::database::turbo::{self};
2123
pub use crate::{
2224
backend::{BackendOptions, StorageMode, TurboTasksBackend},
2325
backing_storage::BackingStorage,
@@ -29,11 +31,16 @@ pub use crate::{
2931
kv_backing_storage::KeyValueDatabaseBackingStorage,
3032
};
3133

34+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
3235
pub type TurboBackingStorage = KeyValueDatabaseBackingStorage<TurboKeyValueDatabase>;
3336

3437
/// Creates a `BackingStorage` to be passed to [`TurboTasksBackend::new`].
3538
///
3639
/// Information about the state of the on-disk cache is returned using [`StartupCacheState`].
40+
///
41+
/// This is the fastest most-tested implementation of `BackingStorage`, and is normally returned by
42+
/// [`default_backing_storage`].
43+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
3744
pub fn turbo_backing_storage(
3845
base_path: &Path,
3946
version_info: &GitVersionInfo,
@@ -62,6 +69,7 @@ pub fn noop_backing_storage() -> NoopBackingStorage {
6269
///
6370
/// The parallel scheduler requires a Tokio runtime. If one is already active (e.g. when called
6471
/// from a NAPI async function), it is reused. Otherwise a new multi-threaded runtime is created.
72+
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
6573
pub fn compact_database(
6674
base_path: &Path,
6775
version_info: &GitVersionInfo,

0 commit comments

Comments
 (0)