Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(turbopack): Use ResolvedVc for turbopack-dev-server #73195

Merged
merged 59 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0ffba2d
ResolvedVc<T>
kdy1 Nov 26, 2024
33cbc2d
ResolvedVc<T>
kdy1 Nov 26, 2024
0cf4541
ResolvedVc<T>
kdy1 Nov 26, 2024
8c8e2d8
ResolvedVc<T>
kdy1 Nov 26, 2024
2b7f4e0
ResolvedVc<T>
kdy1 Nov 26, 2024
6a456af
ResolvedVc<T>
kdy1 Nov 26, 2024
90291b9
ResolvedVc<T>
kdy1 Nov 26, 2024
8f0e36f
ResolvedVc<T>
kdy1 Nov 26, 2024
733bf55
ResolvedVc<T>
kdy1 Nov 26, 2024
32c5d1b
ResolvedVc<T>
kdy1 Nov 26, 2024
970cbd5
ResolvedVc<T>
kdy1 Nov 26, 2024
4b23f61
ResolvedVc<T>
kdy1 Nov 26, 2024
ac389a6
ResolvedVc<T>
kdy1 Nov 26, 2024
ff7ed1d
Fix more
kdy1 Nov 26, 2024
3237745
Fix more
kdy1 Nov 26, 2024
acae2b2
Fix more
kdy1 Nov 26, 2024
593e9b6
Fix more
kdy1 Nov 26, 2024
05872e7
Fix more
kdy1 Nov 26, 2024
ef67698
Fix more
kdy1 Nov 26, 2024
45357cc
Fix more
kdy1 Nov 26, 2024
7ab304d
Fix more
kdy1 Nov 26, 2024
1a6cf90
Fix more
kdy1 Nov 26, 2024
9e29d25
Fix more
kdy1 Nov 26, 2024
dc3749a
Fix more
kdy1 Nov 26, 2024
947d936
Fix more
kdy1 Nov 26, 2024
62950cc
Fix more
kdy1 Nov 26, 2024
6d1cc28
Fix more
kdy1 Nov 26, 2024
7b69678
Fix more
kdy1 Nov 26, 2024
63ca0bd
Fix more
kdy1 Nov 26, 2024
94c7322
Fix more
kdy1 Nov 26, 2024
01a592c
Fix more
kdy1 Nov 26, 2024
bd04ea4
Fix more
kdy1 Nov 26, 2024
6071f8b
Fix more
kdy1 Nov 26, 2024
4dcd17e
Fix more
kdy1 Nov 26, 2024
6721f8d
Fix more
kdy1 Nov 26, 2024
ae84681
Fix more
kdy1 Nov 26, 2024
e6d5279
Fix more
kdy1 Nov 26, 2024
757a125
Fix more
kdy1 Nov 26, 2024
3033b50
Fix more
kdy1 Nov 26, 2024
cdfe9e7
Fix more
kdy1 Nov 26, 2024
0da9eab
Fix more
kdy1 Nov 26, 2024
2abafd5
Fix more
kdy1 Nov 26, 2024
5a1d959
Fix more
kdy1 Nov 26, 2024
dda53ef
Fix more
kdy1 Nov 26, 2024
84b4f36
Fix more
kdy1 Nov 26, 2024
8e40e50
Fix more
kdy1 Nov 26, 2024
70ef062
Fix more
kdy1 Nov 26, 2024
208515c
Fix more
kdy1 Nov 27, 2024
e233d05
Fix more
kdy1 Nov 27, 2024
289ffdd
Fix more
kdy1 Nov 27, 2024
10bdb65
Fix more
kdy1 Nov 27, 2024
2242a87
Fix more
kdy1 Nov 27, 2024
5abde8a
Fix more
kdy1 Nov 27, 2024
b144a4a
Fix more
kdy1 Nov 27, 2024
2174ccb
Fix more
kdy1 Nov 27, 2024
397f496
Fix more
kdy1 Nov 27, 2024
d3e26af
Fix more
kdy1 Nov 27, 2024
ceb354f
Fix more
kdy1 Nov 27, 2024
fe4b0bf
Fix more
kdy1 Nov 27, 2024
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
27 changes: 16 additions & 11 deletions turbopack/crates/turbopack-cli/src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use owo_colors::OwoColorize;
use turbo_rcstr::RcStr;
use turbo_tasks::{
util::{FormatBytes, FormatDuration},
TransientInstance, TurboTasks, UpdateInfo, Value, Vc,
ResolvedVc, TransientInstance, TurboTasks, UpdateInfo, Value, Vc,
};
use turbo_tasks_fs::FileSystem;
use turbo_tasks_malloc::TurboMalloc;
Expand Down Expand Up @@ -301,23 +301,28 @@ async fn source(
eager_compile,
NodeEnv::Development.cell(),
browserslist_query,
)
.to_resolved()
.await?;
let static_source = ResolvedVc::upcast(
StaticAssetsContentSource::new(Default::default(), project_path.join("public".into()))
.to_resolved()
.await?,
);
let static_source = Vc::upcast(StaticAssetsContentSource::new(
Default::default(),
project_path.join("public".into()),
));
let main_source = CombinedContentSource::new(vec![static_source, web_source]);
let introspect = Vc::upcast(
let main_source = CombinedContentSource::new(vec![static_source, web_source])
.to_resolved()
.await?;
let introspect = ResolvedVc::upcast(
IntrospectionSource {
roots: HashSet::from([Vc::upcast(main_source)]),
roots: HashSet::from([ResolvedVc::upcast(main_source)]),
}
.cell(),
.resolved_cell(),
);
let main_source = Vc::upcast(main_source);
let main_source = ResolvedVc::upcast(main_source);
Ok(Vc::upcast(PrefixedRouterContentSource::new(
Default::default(),
vec![("__turbopack__".into(), introspect)],
main_source,
*main_source,
)))
}

Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub async fn create_web_entry_source(
.await?;

let entry_asset = Vc::upcast(DevHtmlAsset::new(
server_root.join("index.html".into()),
server_root.join("index.html".into()).to_resolved().await?,
entries,
));

Expand Down
10 changes: 5 additions & 5 deletions turbopack/crates/turbopack-dev-server/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DevHtmlEntry = (
#[turbo_tasks::value(shared)]
#[derive(Clone)]
pub struct DevHtmlAsset {
path: Vc<FileSystemPath>,
path: ResolvedVc<FileSystemPath>,
entries: Vec<DevHtmlEntry>,
body: Option<RcStr>,
}
Expand All @@ -44,7 +44,7 @@ fn dev_html_chunk_reference_description() -> Vc<RcStr> {
impl OutputAsset for DevHtmlAsset {
#[turbo_tasks::function]
fn ident(&self) -> Vc<AssetIdent> {
AssetIdent::from_path(self.path)
AssetIdent::from_path(*self.path)
}

#[turbo_tasks::function]
Expand All @@ -68,7 +68,7 @@ impl Asset for DevHtmlAsset {

impl DevHtmlAsset {
/// Create a new dev HTML asset.
pub fn new(path: Vc<FileSystemPath>, entries: Vec<DevHtmlEntry>) -> Vc<Self> {
pub fn new(path: ResolvedVc<FileSystemPath>, entries: Vec<DevHtmlEntry>) -> Vc<Self> {
DevHtmlAsset {
path,
entries,
Expand All @@ -79,7 +79,7 @@ impl DevHtmlAsset {

/// Create a new dev HTML asset.
pub fn new_with_body(
path: Vc<FileSystemPath>,
path: ResolvedVc<FileSystemPath>,
entries: Vec<DevHtmlEntry>,
body: RcStr,
) -> Vc<Self> {
Expand All @@ -95,7 +95,7 @@ impl DevHtmlAsset {
#[turbo_tasks::value_impl]
impl DevHtmlAsset {
#[turbo_tasks::function]
pub async fn with_path(self: Vc<Self>, path: Vc<FileSystemPath>) -> Result<Vc<Self>> {
pub async fn with_path(self: Vc<Self>, path: ResolvedVc<FileSystemPath>) -> Result<Vc<Self>> {
let mut html: DevHtmlAsset = self.await?.clone_value();
html.path = path;
Ok(html.cell())
Expand Down
26 changes: 15 additions & 11 deletions turbopack/crates/turbopack-dev-server/src/introspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{borrow::Cow, collections::HashSet, fmt::Display};

use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, TryJoinIterExt, Vc};
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_fs::{json::parse_json_with_source_context, File};
use turbopack_core::{
asset::AssetContent,
Expand All @@ -18,7 +18,7 @@ use crate::source::{

#[turbo_tasks::value(shared)]
pub struct IntrospectionSource {
pub roots: HashSet<Vc<Box<dyn Introspectable>>>,
pub roots: HashSet<ResolvedVc<Box<dyn Introspectable>>>,
}

#[turbo_tasks::value_impl]
Expand All @@ -36,7 +36,7 @@ impl Introspectable for IntrospectionSource {
#[turbo_tasks::function]
fn children(&self) -> Vc<IntrospectableChildren> {
let name = Vc::cell("root".into());
Vc::cell(self.roots.iter().map(|root| (name, *root)).collect())
Vc::cell(self.roots.iter().map(|root| (name, **root)).collect())
}
}

Expand Down Expand Up @@ -76,20 +76,24 @@ impl<T: Display> Display for HtmlStringEscaped<T> {
#[turbo_tasks::value_impl]
impl ContentSource for IntrospectionSource {
#[turbo_tasks::function]
fn get_routes(self: Vc<Self>) -> Vc<RouteTree> {
Vc::<RouteTrees>::cell(vec![
RouteTree::new_route(Vec::new(), RouteType::Exact, Vc::upcast(self)),
RouteTree::new_route(Vec::new(), RouteType::CatchAll, Vc::upcast(self)),
async fn get_routes(self: Vc<Self>) -> Result<Vc<RouteTree>> {
Ok(Vc::<RouteTrees>::cell(vec![
RouteTree::new_route(Vec::new(), RouteType::Exact, Vc::upcast(self))
.to_resolved()
.await?,
RouteTree::new_route(Vec::new(), RouteType::CatchAll, Vc::upcast(self))
.to_resolved()
.await?,
])
.merge()
.merge())
}
}

#[turbo_tasks::value_impl]
impl GetContentSourceContent for IntrospectionSource {
#[turbo_tasks::function]
async fn get(
self: Vc<Self>,
self: ResolvedVc<Self>,
path: RcStr,
_data: turbo_tasks::Value<ContentSourceData>,
) -> Result<Vc<ContentSourceContent>> {
Expand All @@ -100,12 +104,12 @@ impl GetContentSourceContent for IntrospectionSource {
if roots.len() == 1 {
*roots.iter().next().unwrap()
} else {
Vc::upcast(self)
ResolvedVc::upcast(self)
}
} else {
parse_json_with_source_context(path)?
};
let internal_ty = Vc::debug_identifier(introspectable).await?;
let internal_ty = Vc::debug_identifier(*introspectable).await?;
fn str_or_err(s: &Result<ReadRef<RcStr>>) -> Cow<'_, str> {
s.as_ref().map_or_else(
|e| Cow::<'_, str>::Owned(format!("ERROR: {:?}", e)),
Expand Down
32 changes: 17 additions & 15 deletions turbopack/crates/turbopack-dev-server/src/source/asset_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type ExpandedState = State<HashSet<RcStr>>;

#[turbo_tasks::value(serialization = "none", eq = "manual", cell = "new")]
pub struct AssetGraphContentSource {
root_path: Vc<FileSystemPath>,
root_assets: Vc<OutputAssetsSet>,
root_path: ResolvedVc<FileSystemPath>,
root_assets: ResolvedVc<OutputAssetsSet>,
expanded: Option<ExpandedState>,
}

Expand All @@ -39,12 +39,12 @@ impl AssetGraphContentSource {
/// Serves all assets references by root_asset.
#[turbo_tasks::function]
pub fn new_eager(
root_path: Vc<FileSystemPath>,
root_path: ResolvedVc<FileSystemPath>,
root_asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Vc<Self> {
Self::cell(AssetGraphContentSource {
root_path,
root_assets: Vc::cell(fxindexset! { root_asset }),
root_assets: ResolvedVc::cell(fxindexset! { root_asset }),
expanded: None,
})
}
Expand All @@ -53,21 +53,21 @@ impl AssetGraphContentSource {
/// asset when it has served its content before.
#[turbo_tasks::function]
pub fn new_lazy(
root_path: Vc<FileSystemPath>,
root_path: ResolvedVc<FileSystemPath>,
root_asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Vc<Self> {
Self::cell(AssetGraphContentSource {
root_path,
root_assets: Vc::cell(fxindexset! { root_asset }),
root_assets: ResolvedVc::cell(fxindexset! { root_asset }),
expanded: Some(State::new(HashSet::new())),
})
}

/// Serves all assets references by all root_assets.
#[turbo_tasks::function]
pub fn new_eager_multiple(
root_path: Vc<FileSystemPath>,
root_assets: Vc<OutputAssetsSet>,
root_path: ResolvedVc<FileSystemPath>,
root_assets: ResolvedVc<OutputAssetsSet>,
) -> Vc<Self> {
Self::cell(AssetGraphContentSource {
root_path,
Expand All @@ -80,8 +80,8 @@ impl AssetGraphContentSource {
/// of an asset when it has served its content before.
#[turbo_tasks::function]
pub fn new_lazy_multiple(
root_path: Vc<FileSystemPath>,
root_assets: Vc<OutputAssetsSet>,
root_path: ResolvedVc<FileSystemPath>,
root_assets: ResolvedVc<OutputAssetsSet>,
) -> Vc<Self> {
Self::cell(AssetGraphContentSource {
root_path,
Expand Down Expand Up @@ -230,25 +230,27 @@ impl ContentSource for AssetGraphContentSource {
)),
)
})
.collect();
.map(|v| async move { v.to_resolved().await })
.try_join()
.await?;
Ok(Vc::<RouteTrees>::cell(routes).merge())
}
}

#[turbo_tasks::value]
struct AssetGraphGetContentSourceContent {
source: Vc<AssetGraphContentSource>,
source: ResolvedVc<AssetGraphContentSource>,
path: RcStr,
asset: Vc<Box<dyn OutputAsset>>,
asset: ResolvedVc<Box<dyn OutputAsset>>,
}

#[turbo_tasks::value_impl]
impl AssetGraphGetContentSourceContent {
#[turbo_tasks::function]
pub fn new(
source: Vc<AssetGraphContentSource>,
source: ResolvedVc<AssetGraphContentSource>,
path: RcStr,
asset: Vc<Box<dyn OutputAsset>>,
asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Vc<Self> {
Self::cell(AssetGraphGetContentSourceContent {
source,
Expand Down
23 changes: 14 additions & 9 deletions turbopack/crates/turbopack-dev-server/src/source/combined.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{TryJoinIterExt, Vc};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbopack_core::introspect::{Introspectable, IntrospectableChildren};

use super::{
Expand All @@ -15,21 +15,26 @@ use crate::source::ContentSources;
/// not a [ContentSourceContent::NotFound]) will be returned.
#[turbo_tasks::value(shared)]
pub struct CombinedContentSource {
pub sources: Vec<Vc<Box<dyn ContentSource>>>,
pub sources: Vec<ResolvedVc<Box<dyn ContentSource>>>,
}

impl CombinedContentSource {
pub fn new(sources: Vec<Vc<Box<dyn ContentSource>>>) -> Vc<Self> {
pub fn new(sources: Vec<ResolvedVc<Box<dyn ContentSource>>>) -> Vc<Self> {
CombinedContentSource { sources }.cell()
}
}

#[turbo_tasks::value_impl]
impl ContentSource for CombinedContentSource {
#[turbo_tasks::function]
fn get_routes(&self) -> Vc<RouteTree> {
let all_routes = self.sources.iter().map(|s| s.get_routes()).collect();
Vc::<RouteTrees>::cell(all_routes).merge()
async fn get_routes(&self) -> Result<Vc<RouteTree>> {
let all_routes = self
.sources
.iter()
.map(|s| async move { s.get_routes().to_resolved().await })
.try_join()
.await?;
Ok(Vc::<RouteTrees>::cell(all_routes).merge())
}

#[turbo_tasks::function]
Expand All @@ -53,7 +58,7 @@ impl Introspectable for CombinedContentSource {
.map(|&source| async move {
Ok(
if let Some(source) =
Vc::try_resolve_sidecast::<Box<dyn Introspectable>>(source).await?
ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(source).await?
{
Some(source.title().await?)
} else {
Expand Down Expand Up @@ -86,13 +91,13 @@ impl Introspectable for CombinedContentSource {
.iter()
.copied()
.map(|s| async move {
Ok(Vc::try_resolve_sidecast::<Box<dyn Introspectable>>(s).await?)
Ok(ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(s).await?)
})
.try_join()
.await?
.into_iter()
.flatten()
.map(|i| (source, i))
.map(|i| (source, *i))
.collect(),
))
}
Expand Down
Loading
Loading