Unverified Commit 251e6bd9 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

perf(turbopack): Migrate as many data structures to FxHash as possible (#75546)

Migrate as many things as possible that I could find with:

```
rg '\b(Index|Hash)(Map|Set)<'
```

# Benchmarks

I tried building next-site, differences are likely within noise threshold.

## Before this change

```
$ hyperfine --warmup 1 --runs 5 --prepare 'rm -rf .next' 'TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile'

Benchmark 1: TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile
  Time (mean ± σ):     27.254 s ±  0.268 s    [User: 125.055 s, System: 16.090 s]
  Range (min … max):   26.810 s … 27.529 s    5 runs
```

## After this change

```
$ hyperfine --warmup 1 --runs 5 --prepare 'rm -rf .next' 'TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile'

Benchmark 1: TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile
  Time (mean ± σ):     26.711 s ±  0.461 s    [User: 123.910 s, System: 15.667 s]
  Range (min … max):   26.346 s … 27.463 s    5 runs
```
parent 883147a9
...@@ -4394,6 +4394,7 @@ dependencies = [ ...@@ -4394,6 +4394,7 @@ dependencies = [
"next-core", "next-core",
"petgraph", "petgraph",
"regex", "regex",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_json", "serde_json",
"shadow-rs", "shadow-rs",
...@@ -9082,6 +9083,7 @@ dependencies = [ ...@@ -9082,6 +9083,7 @@ dependencies = [
"lsp-server", "lsp-server",
"lsp-types", "lsp-types",
"proc-macro2", "proc-macro2",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_json", "serde_json",
"serde_path_to_error", "serde_path_to_error",
...@@ -9176,6 +9178,7 @@ dependencies = [ ...@@ -9176,6 +9178,7 @@ dependencies = [
"cargo-lock", "cargo-lock",
"glob", "glob",
"quote", "quote",
"rustc-hash 2.1.0",
"syn 1.0.109", "syn 1.0.109",
"turbo-tasks-macros-shared", "turbo-tasks-macros-shared",
] ]
...@@ -9248,6 +9251,7 @@ dependencies = [ ...@@ -9248,6 +9251,7 @@ dependencies = [
"parking_lot", "parking_lot",
"rayon", "rayon",
"rstest", "rstest",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_bytes", "serde_bytes",
"serde_json", "serde_json",
...@@ -9283,6 +9287,7 @@ dependencies = [ ...@@ -9283,6 +9287,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex", "regex",
"rustc-hash 2.1.0",
"syn 1.0.109", "syn 1.0.109",
"turbo-tasks-macros-shared", "turbo-tasks-macros-shared",
] ]
...@@ -9418,6 +9423,7 @@ dependencies = [ ...@@ -9418,6 +9423,7 @@ dependencies = [
"portpicker", "portpicker",
"rand", "rand",
"regex", "regex",
"rustc-hash 2.1.0",
"serde_json", "serde_json",
"tempfile", "tempfile",
"tokio", "tokio",
...@@ -9465,6 +9471,7 @@ dependencies = [ ...@@ -9465,6 +9471,7 @@ dependencies = [
"mime", "mime",
"owo-colors 3.5.0", "owo-colors 3.5.0",
"regex", "regex",
"rustc-hash 2.1.0",
"serde", "serde",
"tokio", "tokio",
"tracing", "tracing",
...@@ -9501,6 +9508,7 @@ dependencies = [ ...@@ -9501,6 +9508,7 @@ dependencies = [
"clap", "clap",
"crossterm 0.26.1", "crossterm 0.26.1",
"owo-colors 3.5.0", "owo-colors 3.5.0",
"rustc-hash 2.1.0",
"serde", "serde",
"turbo-tasks", "turbo-tasks",
"turbo-tasks-build", "turbo-tasks-build",
...@@ -9569,6 +9577,7 @@ dependencies = [ ...@@ -9569,6 +9577,7 @@ dependencies = [
"parcel_selectors", "parcel_selectors",
"parcel_sourcemap", "parcel_sourcemap",
"regex", "regex",
"rustc-hash 2.1.0",
"serde", "serde",
"smallvec", "smallvec",
"swc_core", "swc_core",
...@@ -9599,6 +9608,7 @@ dependencies = [ ...@@ -9599,6 +9608,7 @@ dependencies = [
"mime_guess", "mime_guess",
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_json", "serde_json",
"serde_qs", "serde_qs",
...@@ -9737,6 +9747,7 @@ dependencies = [ ...@@ -9737,6 +9747,7 @@ dependencies = [
"mime", "mime",
"once_cell", "once_cell",
"regex", "regex",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_with", "serde_with",
"turbo-tasks", "turbo-tasks",
...@@ -9794,6 +9805,7 @@ dependencies = [ ...@@ -9794,6 +9805,7 @@ dependencies = [
"owo-colors 3.5.0", "owo-colors 3.5.0",
"parking_lot", "parking_lot",
"regex", "regex",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_json", "serde_json",
"serde_with", "serde_with",
...@@ -9887,6 +9899,7 @@ dependencies = [ ...@@ -9887,6 +9899,7 @@ dependencies = [
"anyhow", "anyhow",
"once_cell", "once_cell",
"regex", "regex",
"rustc-hash 2.1.0",
"serde", "serde",
"similar", "similar",
"turbo-rcstr", "turbo-rcstr",
...@@ -9907,6 +9920,7 @@ dependencies = [ ...@@ -9907,6 +9920,7 @@ dependencies = [
"futures", "futures",
"indexmap 2.7.1", "indexmap 2.7.1",
"once_cell", "once_cell",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_json", "serde_json",
"testing", "testing",
...@@ -11547,6 +11561,7 @@ dependencies = [ ...@@ -11547,6 +11561,7 @@ dependencies = [
"num-format", "num-format",
"owo-colors 3.5.0", "owo-colors 3.5.0",
"plotters", "plotters",
"rustc-hash 2.1.0",
"semver 1.0.23", "semver 1.0.23",
"serde", "serde",
"serde_json", "serde_json",
......
use std::{ use std::{future::Future, ops::Deref, path::PathBuf, sync::Arc, time::Duration};
collections::HashMap, future::Future, ops::Deref, path::PathBuf, sync::Arc, time::Duration,
};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use napi::{ use napi::{
...@@ -8,6 +6,7 @@ use napi::{ ...@@ -8,6 +6,7 @@ use napi::{
threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode}, threadsafe_function::{ThreadSafeCallContext, ThreadsafeFunction, ThreadsafeFunctionCallMode},
JsFunction, JsObject, JsUnknown, NapiRaw, NapiValue, Status, JsFunction, JsObject, JsUnknown, NapiRaw, NapiValue, Status,
}; };
use rustc_hash::FxHashMap;
use serde::Serialize; use serde::Serialize;
use turbo_tasks::{ use turbo_tasks::{
task_statistics::TaskStatisticsApi, trace::TraceRawVcs, OperationVc, ReadRef, TaskId, task_statistics::TaskStatisticsApi, trace::TraceRawVcs, OperationVc, ReadRef, TaskId,
...@@ -412,7 +411,8 @@ impl From<SourcePos> for NapiSourcePos { ...@@ -412,7 +411,8 @@ impl From<SourcePos> for NapiSourcePos {
pub struct NapiDiagnostic { pub struct NapiDiagnostic {
pub category: String, pub category: String,
pub name: String, pub name: String,
pub payload: HashMap<String, String>, #[napi(ts_type = "Record<string, string>")]
pub payload: FxHashMap<String, String>,
} }
impl NapiDiagnostic { impl NapiDiagnostic {
......
...@@ -20,9 +20,11 @@ indexmap = { workspace = true } ...@@ -20,9 +20,11 @@ indexmap = { workspace = true }
next-core = { workspace = true } next-core = { workspace = true }
petgraph = { workspace = true, features = ["serde-1"]} petgraph = { workspace = true, features = ["serde-1"]}
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
shadow-rs = { workspace = true } shadow-rs = { workspace = true }
swc_core = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
...@@ -34,11 +36,10 @@ turbopack = { workspace = true } ...@@ -34,11 +36,10 @@ turbopack = { workspace = true }
turbopack-browser = { workspace = true } turbopack-browser = { workspace = true }
turbopack-cli-utils = { workspace = true } turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
turbopack-env = { workspace = true }
turbopack-ecmascript = { workspace = true } turbopack-ecmascript = { workspace = true }
turbopack-env = { workspace = true }
turbopack-node = { workspace = true } turbopack-node = { workspace = true }
turbopack-nodejs = { workspace = true } turbopack-nodejs = { workspace = true }
swc_core = { workspace = true }
[build-dependencies] [build-dependencies]
# It is not a mistake this dependency is specified in dep / build-dep both. # It is not a mistake this dependency is specified in dep / build-dep both.
......
use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use next_core::{ use next_core::{
self, self,
next_client_reference::{CssClientReferenceModule, EcmascriptClientReferenceModule}, next_client_reference::{CssClientReferenceModule, EcmascriptClientReferenceModule},
next_server_component::server_component_module::NextServerComponentModule, next_server_component::server_component_module::NextServerComponentModule,
}; };
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc,
...@@ -26,7 +25,7 @@ pub enum ClientReferenceMapType { ...@@ -26,7 +25,7 @@ pub enum ClientReferenceMapType {
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct ClientReferencesSet(HashMap<ResolvedVc<Box<dyn Module>>, ClientReferenceMapType>); pub struct ClientReferencesSet(FxHashMap<ResolvedVc<Box<dyn Module>>, ClientReferenceMapType>);
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn map_client_references( pub async fn map_client_references(
......
use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use next_core::{next_manifests::LoadableManifest, util::NextRuntime}; use next_core::{next_manifests::LoadableManifest, util::NextRuntime};
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath}; use turbo_tasks_fs::{File, FileContent, FileSystemPath};
...@@ -23,7 +22,7 @@ pub async fn create_react_loadable_manifest( ...@@ -23,7 +22,7 @@ pub async fn create_react_loadable_manifest(
) -> Result<Vc<OutputAssets>> { ) -> Result<Vc<OutputAssets>> {
let dynamic_import_entries = &*dynamic_import_entries.await?; let dynamic_import_entries = &*dynamic_import_entries.await?;
let mut loadable_manifest: HashMap<RcStr, LoadableManifest> = Default::default(); let mut loadable_manifest: FxHashMap<RcStr, LoadableManifest> = FxHashMap::default();
for (_, (module_id, chunk_output)) in dynamic_import_entries.into_iter() { for (_, (module_id, chunk_output)) in dynamic_import_entries.into_iter() {
let chunk_output = chunk_output.await?; let chunk_output = chunk_output.await?;
......
use std::{borrow::Cow, collections::HashMap}; use std::borrow::Cow;
use anyhow::Result; use anyhow::Result;
use next_core::{ use next_core::{
...@@ -9,6 +9,7 @@ use next_core::{ ...@@ -9,6 +9,7 @@ use next_core::{
next_dynamic::NextDynamicEntryModule, next_dynamic::NextDynamicEntryModule,
next_manifests::ActionLayer, next_manifests::ActionLayer,
}; };
use rustc_hash::FxHashMap;
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
CollectiblesSource, FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc, CollectiblesSource, FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc,
...@@ -58,8 +59,8 @@ impl NextDynamicGraph { ...@@ -58,8 +59,8 @@ impl NextDynamicGraph {
// This would clone the graph and allow changing the node weights. We can probably get away // This would clone the graph and allow changing the node weights. We can probably get away
// with keeping the sidecar information separate from the graph itself, though. // with keeping the sidecar information separate from the graph itself, though.
// //
// let mut reduced_modules: HashMap<Vc<Box<dyn Module>>, NodeIndex<u32>> = // let mut reduced_modules: FxHashMap<Vc<Box<dyn Module>>, NodeIndex<u32>> =
// HashMap::new(); let mut reduced_graph = DiGraph::new(); // FxHashMap::default(); let mut reduced_graph = DiGraph::new();
// for idx in graph.node_indices() { // for idx in graph.node_indices() {
// let weight = *graph.node_weight(idx).unwrap(); // let weight = *graph.node_weight(idx).unwrap();
// let new_idx = reduced_graph.add_node(weight); // let new_idx = reduced_graph.add_node(weight);
...@@ -112,7 +113,7 @@ impl NextDynamicGraph { ...@@ -112,7 +113,7 @@ impl NextDynamicGraph {
let mut result = vec![]; let mut result = vec![];
// module -> the client reference entry (if any) // module -> the client reference entry (if any)
let mut state_map = HashMap::new(); let mut state_map = FxHashMap::default();
graph.traverse_edges_from_entries(entries, |parent_info, node| { graph.traverse_edges_from_entries(entries, |parent_info, node| {
let module = node.module; let module = node.module;
let Some((parent_node, _)) = parent_info else { let Some((parent_node, _)) = parent_info else {
...@@ -210,7 +211,7 @@ impl ServerActionsGraph { ...@@ -210,7 +211,7 @@ impl ServerActionsGraph {
return Ok(Vc::cell(Default::default())); return Ok(Vc::cell(Default::default()));
} }
let mut result = HashMap::new(); let mut result = FxHashMap::default();
graph.traverse_from_entry(entry, |node| { graph.traverse_from_entry(entry, |node| {
if let Some(node_data) = data.get(&node.module) { if let Some(node_data) = data.get(&node.module) {
result.insert(node.module, *node_data); result.insert(node.module, *node_data);
...@@ -309,7 +310,7 @@ impl ClientReferencesGraph { ...@@ -309,7 +310,7 @@ impl ClientReferencesGraph {
graph.traverse_edges_from_entries_topological( graph.traverse_edges_from_entries_topological(
entries, entries,
// state_map is `module -> Option< the current so parent server component >` // state_map is `module -> Option< the current so parent server component >`
&mut HashMap::new(), &mut FxHashMap::default(),
|parent_info, node, state_map| { |parent_info, node, state_map| {
let module = node.module; let module = node.module;
let module_type = data.get(&module); let module_type = data.get(&module);
......
use anyhow::Result; use anyhow::Result;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, get_effects, trace::TraceRawVcs, CollectiblesSource, NonLocalValue, debug::ValueDebugFormat, get_effects, trace::TraceRawVcs, CollectiblesSource, FxIndexMap,
OperationVc, ResolvedVc, Vc, NonLocalValue, OperationVc, ResolvedVc, Vc,
}; };
use turbopack_core::{diagnostics::Diagnostic, issue::IssueDescriptionExt}; use turbopack_core::{diagnostics::Diagnostic, issue::IssueDescriptionExt};
...@@ -23,7 +22,7 @@ use crate::{ ...@@ -23,7 +22,7 @@ use crate::{
/// This is needed to call `write_to_disk` which expects an `OperationVc<Endpoint>`. /// This is needed to call `write_to_disk` which expects an `OperationVc<Endpoint>`.
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct EntrypointsOperation { pub struct EntrypointsOperation {
pub routes: IndexMap<RcStr, RouteOperation>, pub routes: FxIndexMap<RcStr, RouteOperation>,
pub middleware: Option<MiddlewareOperation>, pub middleware: Option<MiddlewareOperation>,
pub instrumentation: Option<InstrumentationOperation>, pub instrumentation: Option<InstrumentationOperation>,
pub pages_document_endpoint: OperationVc<Box<dyn Endpoint>>, pub pages_document_endpoint: OperationVc<Box<dyn Endpoint>>,
......
use std::{ use std::{collections::BTreeMap, io::Write};
collections::{BTreeMap, HashMap},
io::Write,
};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use next_core::{ use next_core::{
...@@ -10,6 +7,7 @@ use next_core::{ ...@@ -10,6 +7,7 @@ use next_core::{
}, },
util::NextRuntime, util::NextRuntime,
}; };
use rustc_hash::FxHashMap;
use swc_core::{ use swc_core::{
atoms::Atom, atoms::Atom,
common::comments::Comments, common::comments::Comments,
...@@ -399,7 +397,7 @@ struct OptionActionMap(Option<ResolvedVc<ActionMap>>); ...@@ -399,7 +397,7 @@ struct OptionActionMap(Option<ResolvedVc<ActionMap>>);
type LayerAndActions = (ActionLayer, ResolvedVc<ActionMap>); type LayerAndActions = (ActionLayer, ResolvedVc<ActionMap>);
/// A mapping of every module module containing Server Actions, mapping to its layer and actions. /// A mapping of every module module containing Server Actions, mapping to its layer and actions.
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct AllModuleActions(HashMap<ResolvedVc<Box<dyn Module>>, LayerAndActions>); pub struct AllModuleActions(FxHashMap<ResolvedVc<Box<dyn Module>>, LayerAndActions>);
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn map_server_actions(graph: Vc<SingleModuleGraph>) -> Result<Vc<AllModuleActions>> { pub async fn map_server_actions(graph: Vc<SingleModuleGraph>) -> Result<Vc<AllModuleActions>> {
......
use std::collections::{HashMap, HashSet};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use next_core::emit_assets; use next_core::emit_assets;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
...@@ -31,7 +30,7 @@ use turbopack_core::{ ...@@ -31,7 +30,7 @@ use turbopack_core::{
struct MapEntry { struct MapEntry {
assets_operation: OperationVc<OutputAssets>, assets_operation: OperationVc<OutputAssets>,
/// Precomputed map for quick access to output asset by filepath /// Precomputed map for quick access to output asset by filepath
path_to_asset: HashMap<ResolvedVc<FileSystemPath>, ResolvedVc<Box<dyn OutputAsset>>>, path_to_asset: FxHashMap<ResolvedVc<FileSystemPath>, ResolvedVc<Box<dyn OutputAsset>>>,
} }
// HACK: This is technically incorrect because `path_to_asset` contains `ResolvedVc`... // HACK: This is technically incorrect because `path_to_asset` contains `ResolvedVc`...
...@@ -49,7 +48,7 @@ pub struct PathToOutputOperation( ...@@ -49,7 +48,7 @@ pub struct PathToOutputOperation(
/// It may not be 100% correct for the key (`FileSystemPath`) to be in a `ResolvedVc` here, but /// It may not be 100% correct for the key (`FileSystemPath`) to be in a `ResolvedVc` here, but
/// it's impractical to make it an `OperationVc`/`OperationValue`, and it's unlikely to /// it's impractical to make it an `OperationVc`/`OperationValue`, and it's unlikely to
/// change/break? /// change/break?
HashMap<ResolvedVc<FileSystemPath>, FxIndexSet<OperationVc<OutputAssets>>>, FxHashMap<ResolvedVc<FileSystemPath>, FxIndexSet<OperationVc<OutputAssets>>>,
); );
// HACK: This is technically incorrect because the map's key is a `ResolvedVc`... // HACK: This is technically incorrect because the map's key is a `ResolvedVc`...
...@@ -57,7 +56,7 @@ unsafe impl OperationValue for PathToOutputOperation {} ...@@ -57,7 +56,7 @@ unsafe impl OperationValue for PathToOutputOperation {}
// A precomputed map for quick access to output asset by filepath // A precomputed map for quick access to output asset by filepath
type OutputOperationToComputeEntry = type OutputOperationToComputeEntry =
HashMap<OperationVc<OutputAssets>, OperationVc<OptionMapEntry>>; FxHashMap<OperationVc<OutputAssets>, OperationVc<OptionMapEntry>>;
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct VersionedContentMap { pub struct VersionedContentMap {
...@@ -77,8 +76,8 @@ impl VersionedContentMap { ...@@ -77,8 +76,8 @@ impl VersionedContentMap {
// should be a singleton for each project. // should be a singleton for each project.
pub fn new() -> ResolvedVc<Self> { pub fn new() -> ResolvedVc<Self> {
VersionedContentMap { VersionedContentMap {
map_path_to_op: State::new(PathToOutputOperation(HashMap::new())), map_path_to_op: State::new(PathToOutputOperation(FxHashMap::default())),
map_op_to_compute_entry: State::new(HashMap::new()), map_op_to_compute_entry: State::new(FxHashMap::default()),
} }
.resolved_cell() .resolved_cell()
} }
...@@ -142,7 +141,7 @@ impl VersionedContentMap { ...@@ -142,7 +141,7 @@ impl VersionedContentMap {
let mut changed = false; let mut changed = false;
// get current map's keys, subtract keys that don't exist in operation // get current map's keys, subtract keys that don't exist in operation
let mut stale_assets = map.0.keys().copied().collect::<HashSet<_>>(); let mut stale_assets = map.0.keys().copied().collect::<FxHashSet<_>>();
for (k, _) in entries.iter() { for (k, _) in entries.iter() {
let res = map.0.entry(*k).or_default().insert(assets_operation); let res = map.0.entry(*k).or_default().insert(assets_operation);
......
use std::{collections::HashMap, ops::Deref}; use std::ops::Deref;
use anyhow::Result; use anyhow::Result;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::Vc; use turbo_tasks::Vc;
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
...@@ -11,9 +12,9 @@ use crate::next_app::{AppPage, PageSegment, PageType}; ...@@ -11,9 +12,9 @@ use crate::next_app::{AppPage, PageSegment, PageType};
pub mod image; pub mod image;
pub mod route; pub mod route;
pub static STATIC_LOCAL_METADATA: Lazy<HashMap<&'static str, &'static [&'static str]>> = pub static STATIC_LOCAL_METADATA: Lazy<FxHashMap<&'static str, &'static [&'static str]>> =
Lazy::new(|| { Lazy::new(|| {
HashMap::from([ FxHashMap::from_iter([
( (
"icon", "icon",
&["ico", "jpg", "jpeg", "png", "svg"] as &'static [&'static str], &["ico", "jpg", "jpeg", "png", "svg"] as &'static [&'static str],
...@@ -25,9 +26,9 @@ pub static STATIC_LOCAL_METADATA: Lazy<HashMap<&'static str, &'static [&'static ...@@ -25,9 +26,9 @@ pub static STATIC_LOCAL_METADATA: Lazy<HashMap<&'static str, &'static [&'static
]) ])
}); });
pub static STATIC_GLOBAL_METADATA: Lazy<HashMap<&'static str, &'static [&'static str]>> = pub static STATIC_GLOBAL_METADATA: Lazy<FxHashMap<&'static str, &'static [&'static str]>> =
Lazy::new(|| { Lazy::new(|| {
HashMap::from([ FxHashMap::from_iter([
("favicon", &["ico"] as &'static [&'static str]), ("favicon", &["ico"] as &'static [&'static str]),
("manifest", &["webmanifest", "json"]), ("manifest", &["webmanifest", "json"]),
("robots", &["txt"]), ("robots", &["txt"]),
...@@ -52,7 +53,7 @@ fn match_numbered_metadata(stem: &str) -> Option<(&str, &str)> { ...@@ -52,7 +53,7 @@ fn match_numbered_metadata(stem: &str) -> Option<(&str, &str)> {
fn match_metadata_file<'a>( fn match_metadata_file<'a>(
filename: &'a str, filename: &'a str,
page_extensions: &[RcStr], page_extensions: &[RcStr],
metadata: &HashMap<&str, &[&str]>, metadata: &FxHashMap<&str, &[&str]>,
) -> Option<MetadataFileMatch<'a>> { ) -> Option<MetadataFileMatch<'a>> {
let (stem, ext) = filename.split_once('.')?; let (stem, ext) = filename.split_once('.')?;
......
use std::{collections::HashSet, future::Future}; use std::future::Future;
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -97,7 +98,7 @@ impl Default for ClientReferenceGraphResult { ...@@ -97,7 +98,7 @@ impl Default for ClientReferenceGraphResult {
} }
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct VisitedClientReferenceGraphNodes(HashSet<VisitClientReferenceNode>); pub struct VisitedClientReferenceGraphNodes(FxHashSet<VisitClientReferenceNode>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl VisitedClientReferenceGraphNodes { impl VisitedClientReferenceGraphNodes {
......
use std::collections::HashSet;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
...@@ -1137,7 +1135,7 @@ impl NextConfig { ...@@ -1137,7 +1135,7 @@ impl NextConfig {
if turbo_rules.is_empty() { if turbo_rules.is_empty() {
return Vc::cell(None); return Vc::cell(None);
} }
let active_conditions = active_conditions.into_iter().collect::<HashSet<_>>(); let active_conditions = active_conditions.into_iter().collect::<FxHashSet<_>>();
let mut rules = FxIndexMap::default(); let mut rules = FxIndexMap::default();
for (ext, rule) in turbo_rules.iter() { for (ext, rule) in turbo_rules.iter() {
fn transform_loaders(loaders: &[LoaderItem]) -> ResolvedVc<WebpackLoaderItems> { fn transform_loaders(loaders: &[LoaderItem]) -> ResolvedVc<WebpackLoaderItems> {
...@@ -1161,7 +1159,7 @@ impl NextConfig { ...@@ -1161,7 +1159,7 @@ impl NextConfig {
} }
fn find_rule<'a>( fn find_rule<'a>(
rule: &'a RuleConfigItem, rule: &'a RuleConfigItem,
active_conditions: &HashSet<RcStr>, active_conditions: &FxHashSet<RcStr>,
) -> FindRuleResult<'a> { ) -> FindRuleResult<'a> {
match rule { match rule {
RuleConfigItem::Options(rule) => FindRuleResult::Found(rule), RuleConfigItem::Options(rule) => FindRuleResult::Found(rule),
......
//! The following code was mostly generated using GTP-4 from //! The following code was mostly generated using GTP-4 from
//! next.js/packages/next/src/shared/lib/router/utils/route-regex.ts //! next.js/packages/next/src/shared/lib/router/utils/route-regex.ts
use std::collections::HashMap;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use rustc_hash::FxHashMap;
const INTERCEPTION_ROUTE_MARKERS: [&str; 4] = ["(..)(..)", "(.)", "(..)", "(...)"]; const INTERCEPTION_ROUTE_MARKERS: [&str; 4] = ["(..)(..)", "(.)", "(..)", "(...)"];
const NEXT_QUERY_PARAM_PREFIX: &str = "nxtP"; const NEXT_QUERY_PARAM_PREFIX: &str = "nxtP";
...@@ -19,7 +18,7 @@ pub struct Group { ...@@ -19,7 +18,7 @@ pub struct Group {
#[derive(Debug)] #[derive(Debug)]
pub struct RouteRegex { pub struct RouteRegex {
pub groups: HashMap<String, Group>, pub groups: FxHashMap<String, Group>,
pub regex: String, pub regex: String,
} }
...@@ -27,7 +26,7 @@ pub struct RouteRegex { ...@@ -27,7 +26,7 @@ pub struct RouteRegex {
pub struct NamedRouteRegex { pub struct NamedRouteRegex {
pub regex: RouteRegex, pub regex: RouteRegex,
pub named_regex: String, pub named_regex: String,
pub route_keys: HashMap<String, String>, pub route_keys: FxHashMap<String, String>,
} }
#[derive(Debug)] #[derive(Debug)]
...@@ -83,9 +82,9 @@ fn remove_trailing_slash(route: &str) -> &str { ...@@ -83,9 +82,9 @@ fn remove_trailing_slash(route: &str) -> &str {
static PARAM_MATCH_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\[((?:\[.*\])|.+)\]").unwrap()); static PARAM_MATCH_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\[((?:\[.*\])|.+)\]").unwrap());
fn get_parametrized_route(route: &str) -> (String, HashMap<String, Group>) { fn get_parametrized_route(route: &str) -> (String, FxHashMap<String, Group>) {
let segments: Vec<&str> = remove_trailing_slash(route)[1..].split('/').collect(); let segments: Vec<&str> = remove_trailing_slash(route)[1..].split('/').collect();
let mut groups: HashMap<String, Group> = HashMap::new(); let mut groups: FxHashMap<String, Group> = FxHashMap::default();
let mut group_index = 1; let mut group_index = 1;
let parameterized_route = segments let parameterized_route = segments
.iter() .iter()
...@@ -163,7 +162,7 @@ fn build_get_safe_route_key() -> impl FnMut() -> String { ...@@ -163,7 +162,7 @@ fn build_get_safe_route_key() -> impl FnMut() -> String {
fn get_safe_key_from_segment( fn get_safe_key_from_segment(
get_safe_route_key: &mut impl FnMut() -> String, get_safe_route_key: &mut impl FnMut() -> String,
segment: &str, segment: &str,
route_keys: &mut HashMap<String, String>, route_keys: &mut FxHashMap<String, String>,
key_prefix: Option<&'static str>, key_prefix: Option<&'static str>,
) -> String { ) -> String {
let ParsedParameter { let ParsedParameter {
...@@ -207,10 +206,10 @@ fn get_safe_key_from_segment( ...@@ -207,10 +206,10 @@ fn get_safe_key_from_segment(
fn get_named_parametrized_route( fn get_named_parametrized_route(
route: &str, route: &str,
prefix_route_keys: bool, prefix_route_keys: bool,
) -> (String, HashMap<String, String>) { ) -> (String, FxHashMap<String, String>) {
let segments: Vec<&str> = remove_trailing_slash(route)[1..].split('/').collect(); let segments: Vec<&str> = remove_trailing_slash(route)[1..].split('/').collect();
let get_safe_route_key = &mut build_get_safe_route_key(); let get_safe_route_key = &mut build_get_safe_route_key();
let mut route_keys: HashMap<String, String> = HashMap::new(); let mut route_keys: FxHashMap<String, String> = FxHashMap::default();
let parameterized_route = segments let parameterized_route = segments
.iter() .iter()
.map(|segment| { .map(|segment| {
......
use std::collections::HashMap;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc, Vc}; use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc, Vc};
...@@ -35,7 +34,7 @@ pub(super) struct FontMetricsMapEntry { ...@@ -35,7 +34,7 @@ pub(super) struct FontMetricsMapEntry {
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub(super) struct FontMetricsMap(pub HashMap<RcStr, FontMetricsMapEntry>); pub(super) struct FontMetricsMap(pub FxHashMap<RcStr, FontMetricsMapEntry>);
#[derive(Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] #[derive(Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)]
struct Fallback { struct Fallback {
......
use std::{collections::HashMap, path::Path}; use std::path::Path;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use futures::FutureExt; use futures::FutureExt;
use indoc::formatdoc; use indoc::formatdoc;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Value, Vc}; use turbo_tasks::{Completion, FxIndexMap, ResolvedVc, Value, Vc};
...@@ -710,7 +711,8 @@ async fn get_mock_stylesheet( ...@@ -710,7 +711,8 @@ async fn get_mock_stylesheet(
match &val.try_into_single().await? { match &val.try_into_single().await? {
SingleValue::Single(val) => { SingleValue::Single(val) => {
let val: HashMap<RcStr, Option<RcStr>> = parse_json_with_source_context(val.to_str()?)?; let val: FxHashMap<RcStr, Option<RcStr>> =
parse_json_with_source_context(val.to_str()?)?;
Ok(val Ok(val
.get(&*stylesheet_url.await?) .get(&*stylesheet_url.await?)
.context("url not found")? .context("url not found")?
......
use std::collections::{BTreeMap, HashMap}; use std::collections::BTreeMap;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{fxindexmap, FxIndexMap, ResolvedVc, Value, Vc}; use turbo_tasks::{fxindexmap, FxIndexMap, ResolvedVc, Value, Vc};
use turbo_tasks_fs::{FileSystem, FileSystemPath}; use turbo_tasks_fs::{FileSystem, FileSystemPath};
...@@ -1051,7 +1052,7 @@ fn export_value_to_import_mapping( ...@@ -1051,7 +1052,7 @@ fn export_value_to_import_mapping(
value.add_results( value.add_results(
conditions, conditions,
&ConditionValue::Unset, &ConditionValue::Unset,
&mut HashMap::new(), &mut FxHashMap::default(),
&mut result, &mut result,
); );
if result.is_empty() { if result.is_empty() {
......
use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use either::Either; use either::Either;
use indoc::formatdoc; use indoc::formatdoc;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -98,7 +97,7 @@ impl ClientReferenceManifest { ...@@ -98,7 +97,7 @@ impl ClientReferenceManifest {
let rsc_app_entry_chunks = &*rsc_app_entry_chunks.await?; let rsc_app_entry_chunks = &*rsc_app_entry_chunks.await?;
async fn cached_chunk_paths( async fn cached_chunk_paths(
cache: &mut HashMap<ResolvedVc<Box<dyn OutputAsset>>, ReadRef<FileSystemPath>>, cache: &mut FxHashMap<ResolvedVc<Box<dyn OutputAsset>>, ReadRef<FileSystemPath>>,
chunks: impl Iterator<Item = ResolvedVc<Box<dyn OutputAsset>>>, chunks: impl Iterator<Item = ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result< ) -> Result<
impl Iterator<Item = (ResolvedVc<Box<dyn OutputAsset>>, ReadRef<FileSystemPath>)>, impl Iterator<Item = (ResolvedVc<Box<dyn OutputAsset>>, ReadRef<FileSystemPath>)>,
...@@ -126,18 +125,18 @@ impl ClientReferenceManifest { ...@@ -126,18 +125,18 @@ impl ClientReferenceManifest {
Either::Right(path) => (chunk, path), Either::Right(path) => (chunk, path),
})) }))
} }
let mut client_chunk_path_cache: HashMap< let mut client_chunk_path_cache: FxHashMap<
ResolvedVc<Box<dyn OutputAsset>>, ResolvedVc<Box<dyn OutputAsset>>,
ReadRef<FileSystemPath>, ReadRef<FileSystemPath>,
> = HashMap::new(); > = FxHashMap::default();
let mut ssr_chunk_path_cache: HashMap< let mut ssr_chunk_path_cache: FxHashMap<
ResolvedVc<Box<dyn OutputAsset>>, ResolvedVc<Box<dyn OutputAsset>>,
ReadRef<FileSystemPath>, ReadRef<FileSystemPath>,
> = HashMap::new(); > = FxHashMap::default();
let mut rsc_chunk_path_cache: HashMap< let mut rsc_chunk_path_cache: FxHashMap<
ResolvedVc<Box<dyn OutputAsset>>, ResolvedVc<Box<dyn OutputAsset>>,
ReadRef<FileSystemPath>, ReadRef<FileSystemPath>,
> = HashMap::new(); > = FxHashMap::default();
for app_client_reference in client_references.await?.client_references.iter() { for app_client_reference in client_references.await?.client_references.iter() {
let app_client_reference_ty = app_client_reference.ty(); let app_client_reference_ty = app_client_reference.ty();
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
pub mod client_reference_manifest; pub mod client_reference_manifest;
use std::collections::HashMap;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
...@@ -23,7 +22,7 @@ use crate::next_config::{CrossOriginConfig, Rewrites, RouteHas}; ...@@ -23,7 +22,7 @@ use crate::next_config::{CrossOriginConfig, Rewrites, RouteHas};
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
pub struct PagesManifest { pub struct PagesManifest {
#[serde(flatten)] #[serde(flatten)]
pub pages: HashMap<RcStr, RcStr>, pub pages: FxHashMap<RcStr, RcStr>,
} }
#[derive(Debug, Default)] #[derive(Debug, Default)]
...@@ -234,16 +233,16 @@ pub enum Regions { ...@@ -234,16 +233,16 @@ pub enum Regions {
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
pub struct MiddlewaresManifestV2 { pub struct MiddlewaresManifestV2 {
pub sorted_middleware: Vec<RcStr>, pub sorted_middleware: Vec<RcStr>,
pub middleware: HashMap<RcStr, EdgeFunctionDefinition>, pub middleware: FxHashMap<RcStr, EdgeFunctionDefinition>,
pub instrumentation: Option<InstrumentationDefinition>, pub instrumentation: Option<InstrumentationDefinition>,
pub functions: HashMap<RcStr, EdgeFunctionDefinition>, pub functions: FxHashMap<RcStr, EdgeFunctionDefinition>,
} }
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ReactLoadableManifest { pub struct ReactLoadableManifest {
#[serde(flatten)] #[serde(flatten)]
pub manifest: HashMap<RcStr, ReactLoadableManifestEntry>, pub manifest: FxHashMap<RcStr, ReactLoadableManifestEntry>,
} }
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
...@@ -256,8 +255,8 @@ pub struct ReactLoadableManifestEntry { ...@@ -256,8 +255,8 @@ pub struct ReactLoadableManifestEntry {
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct NextFontManifest { pub struct NextFontManifest {
pub pages: HashMap<RcStr, Vec<RcStr>>, pub pages: FxHashMap<RcStr, Vec<RcStr>>,
pub app: HashMap<RcStr, Vec<RcStr>>, pub app: FxHashMap<RcStr, Vec<RcStr>>,
pub app_using_size_adjust: bool, pub app_using_size_adjust: bool,
pub pages_using_size_adjust: bool, pub pages_using_size_adjust: bool,
} }
...@@ -286,9 +285,9 @@ pub struct LoadableManifest { ...@@ -286,9 +285,9 @@ pub struct LoadableManifest {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ServerReferenceManifest<'a> { pub struct ServerReferenceManifest<'a> {
/// A map from hashed action name to the runtime module we that exports it. /// A map from hashed action name to the runtime module we that exports it.
pub node: HashMap<&'a str, ActionManifestEntry<'a>>, pub node: FxHashMap<&'a str, ActionManifestEntry<'a>>,
/// A map from hashed action name to the runtime module we that exports it. /// A map from hashed action name to the runtime module we that exports it.
pub edge: HashMap<&'a str, ActionManifestEntry<'a>>, pub edge: FxHashMap<&'a str, ActionManifestEntry<'a>>,
} }
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
...@@ -296,9 +295,9 @@ pub struct ServerReferenceManifest<'a> { ...@@ -296,9 +295,9 @@ pub struct ServerReferenceManifest<'a> {
pub struct ActionManifestEntry<'a> { pub struct ActionManifestEntry<'a> {
/// A mapping from the page that uses the server action to the runtime /// A mapping from the page that uses the server action to the runtime
/// module that exports it. /// module that exports it.
pub workers: HashMap<&'a str, ActionManifestWorkerEntry<'a>>, pub workers: FxHashMap<&'a str, ActionManifestWorkerEntry<'a>>,
pub layer: HashMap<&'a str, ActionLayer>, pub layer: FxHashMap<&'a str, ActionLayer>,
} }
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
...@@ -346,22 +345,22 @@ pub struct ClientReferenceManifest { ...@@ -346,22 +345,22 @@ pub struct ClientReferenceManifest {
pub client_modules: ManifestNode, pub client_modules: ManifestNode,
/// Mapping of client module ID to corresponding SSR module ID and required /// Mapping of client module ID to corresponding SSR module ID and required
/// SSR chunks. /// SSR chunks.
pub ssr_module_mapping: HashMap<ModuleId, ManifestNode>, pub ssr_module_mapping: FxHashMap<ModuleId, ManifestNode>,
/// Same as `ssr_module_mapping`, but for Edge SSR. /// Same as `ssr_module_mapping`, but for Edge SSR.
#[serde(rename = "edgeSSRModuleMapping")] #[serde(rename = "edgeSSRModuleMapping")]
pub edge_ssr_module_mapping: HashMap<ModuleId, ManifestNode>, pub edge_ssr_module_mapping: FxHashMap<ModuleId, ManifestNode>,
/// Mapping of client module ID to corresponding RSC module ID and required /// Mapping of client module ID to corresponding RSC module ID and required
/// RSC chunks. /// RSC chunks.
pub rsc_module_mapping: HashMap<ModuleId, ManifestNode>, pub rsc_module_mapping: FxHashMap<ModuleId, ManifestNode>,
/// Same as `rsc_module_mapping`, but for Edge RSC. /// Same as `rsc_module_mapping`, but for Edge RSC.
#[serde(rename = "edgeRscModuleMapping")] #[serde(rename = "edgeRscModuleMapping")]
pub edge_rsc_module_mapping: HashMap<ModuleId, ManifestNode>, pub edge_rsc_module_mapping: FxHashMap<ModuleId, ManifestNode>,
/// Mapping of server component path to required CSS client chunks. /// Mapping of server component path to required CSS client chunks.
#[serde(rename = "entryCSSFiles")] #[serde(rename = "entryCSSFiles")]
pub entry_css_files: HashMap<RcStr, FxIndexSet<CssResource>>, pub entry_css_files: FxHashMap<RcStr, FxIndexSet<CssResource>>,
/// Mapping of server component path to required JS client chunks. /// Mapping of server component path to required JS client chunks.
#[serde(rename = "entryJSFiles")] #[serde(rename = "entryJSFiles")]
pub entry_js_files: HashMap<RcStr, FxIndexSet<RcStr>>, pub entry_js_files: FxHashMap<RcStr, FxIndexSet<RcStr>>,
} }
#[derive(Serialize, Debug, Clone, Eq, Hash, PartialEq)] #[derive(Serialize, Debug, Clone, Eq, Hash, PartialEq)]
...@@ -384,7 +383,7 @@ pub struct ModuleLoading { ...@@ -384,7 +383,7 @@ pub struct ModuleLoading {
pub struct ManifestNode { pub struct ManifestNode {
/// Mapping of export name to manifest node entry. /// Mapping of export name to manifest node entry.
#[serde(flatten)] #[serde(flatten)]
pub module_exports: HashMap<RcStr, ManifestNodeEntry>, pub module_exports: FxHashMap<RcStr, ManifestNodeEntry>,
} }
#[derive(Serialize, Debug, Clone)] #[derive(Serialize, Debug, Clone)]
...@@ -491,7 +490,7 @@ pub struct ClientBuildManifest<'a> { ...@@ -491,7 +490,7 @@ pub struct ClientBuildManifest<'a> {
pub sorted_pages: &'a [RcStr], pub sorted_pages: &'a [RcStr],
#[serde(flatten)] #[serde(flatten)]
pub pages: HashMap<RcStr, Vec<&'a str>>, pub pages: FxHashMap<RcStr, Vec<&'a str>>,
} }
#[cfg(test)] #[cfg(test)]
......
use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, Vc}; use turbo_tasks::{ResolvedVc, Value, Vc};
use turbo_tasks_fs::{glob::Glob, FileSystemPath}; use turbo_tasks_fs::{glob::Glob, FileSystemPath};
...@@ -24,7 +23,7 @@ use crate::{next_server::ServerContextType, next_telemetry::ModuleFeatureTelemet ...@@ -24,7 +23,7 @@ use crate::{next_server::ServerContextType, next_telemetry::ModuleFeatureTelemet
lazy_static! { lazy_static! {
// Set of the features we want to track, following existing references in webpack/plugins/telemetry-plugin. // Set of the features we want to track, following existing references in webpack/plugins/telemetry-plugin.
static ref FEATURE_MODULES: HashMap<&'static str, Vec<&'static str>> = HashMap::from([ static ref FEATURE_MODULES: FxHashMap<&'static str, Vec<&'static str>> = FxHashMap::from_iter([
( (
"next", "next",
vec![ vec![
......
//! The following code is adapted from sorted-routes.ts using GPT-4 and human //! The following code is adapted from sorted-routes.ts using GPT-4 and human
//! review. //! review.
use std::collections::HashMap; use rustc_hash::FxHashMap;
use thiserror::Error; use thiserror::Error;
#[derive(Debug, Error)] #[derive(Debug, Error)]
...@@ -43,7 +42,7 @@ pub enum UrlNodeError { ...@@ -43,7 +42,7 @@ pub enum UrlNodeError {
pub struct UrlNode { pub struct UrlNode {
placeholder: bool, placeholder: bool,
children: HashMap<String, UrlNode>, children: FxHashMap<String, UrlNode>,
slug_name: Option<String>, slug_name: Option<String>,
rest_slug_name: Option<String>, rest_slug_name: Option<String>,
optional_rest_slug_name: Option<String>, optional_rest_slug_name: Option<String>,
...@@ -59,7 +58,7 @@ impl UrlNode { ...@@ -59,7 +58,7 @@ impl UrlNode {
pub fn new() -> UrlNode { pub fn new() -> UrlNode {
UrlNode { UrlNode {
placeholder: true, placeholder: true,
children: HashMap::new(), children: FxHashMap::default(),
slug_name: None, slug_name: None,
rest_slug_name: None, rest_slug_name: None,
optional_rest_slug_name: None, optional_rest_slug_name: None,
......
...@@ -32,6 +32,13 @@ DEALINGS IN THE SOFTWARE. ...@@ -32,6 +32,13 @@ DEALINGS IN THE SOFTWARE.
#![feature(arbitrary_self_types)] #![feature(arbitrary_self_types)]
#![feature(arbitrary_self_types_pointers)] #![feature(arbitrary_self_types_pointers)]
use std::hash::BuildHasherDefault;
use indexmap::IndexMap;
use rustc_hash::FxHasher;
pub mod chain_transforms; pub mod chain_transforms;
mod linter; mod linter;
pub mod transforms; pub mod transforms;
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
use std::collections::HashSet; use std::iter::FromIterator;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use rustc_hash::FxHashSet;
use swc_core::{ use swc_core::{
atoms::atom, atoms::atom,
ecma::{ ecma::{
...@@ -15,7 +16,7 @@ use swc_core::{ ...@@ -15,7 +16,7 @@ use swc_core::{
use super::{ExportInfo, ExportInfoWarning}; use super::{ExportInfo, ExportInfoWarning};
lazy_static! { lazy_static! {
static ref EXPORTS_SET: HashSet<&'static str> = HashSet::from([ static ref EXPORTS_SET: FxHashSet<&'static str> = FxHashSet::from_iter([
"getStaticProps", "getStaticProps",
"getServerSideProps", "getServerSideProps",
"generateImageMetadata", "generateImageMetadata",
......
use std::{ use std::{
collections::HashMap,
fmt::{self, Display}, fmt::{self, Display},
iter::FromIterator,
path::PathBuf, path::PathBuf,
rc::Rc, rc::Rc,
sync::Arc, sync::Arc,
}; };
use indexmap::IndexMap;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use rustc_hash::FxHashMap;
use serde::Deserialize; use serde::Deserialize;
use swc_core::{ use swc_core::{
common::{ common::{
...@@ -29,6 +29,7 @@ use swc_core::{ ...@@ -29,6 +29,7 @@ use swc_core::{
}; };
use super::{cjs_finder::contains_cjs, import_analyzer::ImportMap}; use super::{cjs_finder::contains_cjs, import_analyzer::ImportMap};
use crate::FxIndexMap;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(untagged)] #[serde(untagged)]
...@@ -544,10 +545,10 @@ struct ReactServerComponentValidator { ...@@ -544,10 +545,10 @@ struct ReactServerComponentValidator {
filepath: String, filepath: String,
app_dir: Option<PathBuf>, app_dir: Option<PathBuf>,
invalid_server_imports: Vec<JsWord>, invalid_server_imports: Vec<JsWord>,
invalid_server_lib_apis_mapping: HashMap<&'static str, Vec<&'static str>>, invalid_server_lib_apis_mapping: FxHashMap<&'static str, Vec<&'static str>>,
deprecated_apis_mapping: HashMap<&'static str, Vec<&'static str>>, deprecated_apis_mapping: FxHashMap<&'static str, Vec<&'static str>>,
invalid_client_imports: Vec<JsWord>, invalid_client_imports: Vec<JsWord>,
invalid_client_lib_apis_mapping: HashMap<&'static str, Vec<&'static str>>, invalid_client_lib_apis_mapping: FxHashMap<&'static str, Vec<&'static str>>,
pub directive_import_collection: Option<(bool, bool, RcVec<ModuleImports>, RcVec<String>)>, pub directive_import_collection: Option<(bool, bool, RcVec<ModuleImports>, RcVec<String>)>,
imports: ImportMap, imports: ImportMap,
} }
...@@ -573,7 +574,7 @@ impl ReactServerComponentValidator { ...@@ -573,7 +574,7 @@ impl ReactServerComponentValidator {
// react -> [apis] // react -> [apis]
// react-dom -> [apis] // react-dom -> [apis]
// next/navigation -> [apis] // next/navigation -> [apis]
invalid_server_lib_apis_mapping: [ invalid_server_lib_apis_mapping: FxHashMap::from_iter([
( (
"react", "react",
vec![ vec![
...@@ -618,9 +619,8 @@ impl ReactServerComponentValidator { ...@@ -618,9 +619,8 @@ impl ReactServerComponentValidator {
"ServerInsertedHTMLContext", "ServerInsertedHTMLContext",
], ],
), ),
] ]),
.into(), deprecated_apis_mapping: FxHashMap::from_iter([("next/server", vec!["ImageResponse"])]),
deprecated_apis_mapping: [("next/server", vec!["ImageResponse"])].into(),
invalid_server_imports: vec![ invalid_server_imports: vec![
JsWord::from("client-only"), JsWord::from("client-only"),
...@@ -631,7 +631,7 @@ impl ReactServerComponentValidator { ...@@ -631,7 +631,7 @@ impl ReactServerComponentValidator {
invalid_client_imports: vec![JsWord::from("server-only"), JsWord::from("next/headers")], invalid_client_imports: vec![JsWord::from("server-only"), JsWord::from("next/headers")],
invalid_client_lib_apis_mapping: [("next/server", vec!["after"])].into(), invalid_client_lib_apis_mapping: FxHashMap::from_iter([("next/server", vec!["after"])]),
imports: ImportMap::default(), imports: ImportMap::default(),
} }
} }
...@@ -781,8 +781,8 @@ impl ReactServerComponentValidator { ...@@ -781,8 +781,8 @@ impl ReactServerComponentValidator {
let is_layout_or_page = RE.is_match(&self.filepath); let is_layout_or_page = RE.is_match(&self.filepath);
if is_layout_or_page { if is_layout_or_page {
let mut possibly_invalid_exports: IndexMap<String, (InvalidExportKind, Span)> = let mut possibly_invalid_exports: FxIndexMap<String, (InvalidExportKind, Span)> =
IndexMap::new(); FxIndexMap::default();
let mut collect_possibly_invalid_exports = let mut collect_possibly_invalid_exports =
|export_name: &str, span: &Span| match export_name { |export_name: &str, span: &Span| match export_name {
......
use std::{ use std::{
cell::RefCell, cell::RefCell,
collections::{hash_map, BTreeMap, HashSet}, collections::{hash_map, BTreeMap},
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
mem::{replace, take}, mem::{replace, take},
rc::Rc, rc::Rc,
...@@ -161,7 +161,7 @@ pub fn server_actions<C: Comments>( ...@@ -161,7 +161,7 @@ pub fn server_actions<C: Comments>(
private_ctxt: SyntaxContext::empty().apply_mark(Mark::new()), private_ctxt: SyntaxContext::empty().apply_mark(Mark::new()),
arrow_or_fn_expr_ident: None, arrow_or_fn_expr_ident: None,
exported_local_ids: HashSet::new(), exported_local_ids: FxHashSet::default(),
use_cache_telemetry_tracker, use_cache_telemetry_tracker,
}) })
...@@ -218,7 +218,7 @@ struct ServerActions<C: Comments> { ...@@ -218,7 +218,7 @@ struct ServerActions<C: Comments> {
private_ctxt: SyntaxContext, private_ctxt: SyntaxContext,
arrow_or_fn_expr_ident: Option<Ident>, arrow_or_fn_expr_ident: Option<Ident>,
exported_local_ids: HashSet<Id>, exported_local_ids: FxHashSet<Id>,
use_cache_telemetry_tracker: Rc<RefCell<FxHashMap<String, usize>>>, use_cache_telemetry_tracker: Rc<RefCell<FxHashMap<String, usize>>>,
} }
......
...@@ -496,7 +496,7 @@ dependencies = [ ...@@ -496,7 +496,7 @@ dependencies = [
"new_debug_unreachable", "new_debug_unreachable",
"once_cell", "once_cell",
"phf", "phf",
"rustc-hash", "rustc-hash 1.1.0",
"triomphe", "triomphe",
] ]
...@@ -776,6 +776,7 @@ name = "next-error-code-swc-plugin" ...@@ -776,6 +776,7 @@ name = "next-error-code-swc-plugin"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"md5", "md5",
"rustc-hash 2.1.0",
"serde", "serde",
"serde_json", "serde_json",
"swc_core", "swc_core",
...@@ -1112,6 +1113,12 @@ version = "1.1.0" ...@@ -1112,6 +1113,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hash"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.2.3" version = "0.2.3"
...@@ -1301,7 +1308,7 @@ dependencies = [ ...@@ -1301,7 +1308,7 @@ dependencies = [
"data-encoding", "data-encoding",
"debugid", "debugid",
"if_chain", "if_chain",
"rustc-hash", "rustc-hash 1.1.0",
"rustc_version", "rustc_version",
"serde", "serde",
"serde_json", "serde_json",
...@@ -1361,7 +1368,7 @@ dependencies = [ ...@@ -1361,7 +1368,7 @@ dependencies = [
"bumpalo", "bumpalo",
"hashbrown 0.14.5", "hashbrown 0.14.5",
"ptr_meta", "ptr_meta",
"rustc-hash", "rustc-hash 1.1.0",
"triomphe", "triomphe",
] ]
...@@ -1375,7 +1382,7 @@ dependencies = [ ...@@ -1375,7 +1382,7 @@ dependencies = [
"hstr", "hstr",
"once_cell", "once_cell",
"rkyv", "rkyv",
"rustc-hash", "rustc-hash 1.1.0",
"serde", "serde",
] ]
...@@ -1397,7 +1404,7 @@ dependencies = [ ...@@ -1397,7 +1404,7 @@ dependencies = [
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"rkyv", "rkyv",
"rustc-hash", "rustc-hash 1.1.0",
"serde", "serde",
"siphasher", "siphasher",
"sourcemap", "sourcemap",
...@@ -1529,7 +1536,7 @@ dependencies = [ ...@@ -1529,7 +1536,7 @@ dependencies = [
"indexmap", "indexmap",
"once_cell", "once_cell",
"phf", "phf",
"rustc-hash", "rustc-hash 1.1.0",
"serde", "serde",
"smallvec", "smallvec",
"swc_atoms", "swc_atoms",
...@@ -1576,7 +1583,7 @@ dependencies = [ ...@@ -1576,7 +1583,7 @@ dependencies = [
"indexmap", "indexmap",
"num_cpus", "num_cpus",
"once_cell", "once_cell",
"rustc-hash", "rustc-hash 1.1.0",
"ryu-js", "ryu-js",
"swc_atoms", "swc_atoms",
"swc_common", "swc_common",
......
...@@ -7,7 +7,8 @@ edition = "2021" ...@@ -7,7 +7,8 @@ edition = "2021"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
swc_core = { version = "5.0.*", features = ["ecma_plugin_transform"] } md5 = "0.7"
serde_json = "1.0" rustc-hash = "2.1.0"
serde = "1.0" serde = "1.0"
md5 = "0.7" serde_json = "1.0"
\ No newline at end of file swc_core = { version = "5.0.*", features = ["ecma_plugin_transform"] }
use std::{collections::HashMap, fs}; use std::fs;
use rustc_hash::FxHashMap;
use swc_core::{ use swc_core::{
ecma::{ast::*, transforms::testing::test_inline, visit::*}, ecma::{ast::*, transforms::testing::test_inline, visit::*},
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata}, plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
}; };
pub struct TransformVisitor { pub struct TransformVisitor {
errors: HashMap<String, String>, errors: FxHashMap<String, String>,
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
...@@ -240,7 +241,7 @@ pub fn process_transform( ...@@ -240,7 +241,7 @@ pub fn process_transform(
) -> Program { ) -> Program {
let errors_json = fs::read_to_string("/cwd/errors.json") let errors_json = fs::read_to_string("/cwd/errors.json")
.unwrap_or_else(|e| panic!("failed to read errors.json: {}", e)); .unwrap_or_else(|e| panic!("failed to read errors.json: {}", e));
let errors: HashMap<String, String> = serde_json::from_str(&errors_json) let errors: FxHashMap<String, String> = serde_json::from_str(&errors_json)
.unwrap_or_else(|e| panic!("failed to parse errors.json: {}", e)); .unwrap_or_else(|e| panic!("failed to parse errors.json: {}", e));
let mut visitor = TransformVisitor { errors }; let mut visitor = TransformVisitor { errors };
...@@ -252,7 +253,7 @@ pub fn process_transform( ...@@ -252,7 +253,7 @@ pub fn process_transform(
test_inline!( test_inline!(
Default::default(), Default::default(),
|_| visit_mut_pass(TransformVisitor { |_| visit_mut_pass(TransformVisitor {
errors: HashMap::from([ errors: FxHashMap::from_iter([
("1".to_string(), "Failed to fetch user %s: %s".to_string()), ("1".to_string(), "Failed to fetch user %s: %s".to_string()),
("2".to_string(), "Request failed: %s".to_string()), ("2".to_string(), "Request failed: %s".to_string()),
("3".to_string(), "Generic error".to_string()), ("3".to_string(), "Generic error".to_string()),
......
...@@ -10,17 +10,18 @@ ...@@ -10,17 +10,18 @@
//! # Example //! # Example
//! //!
//! ``` //! ```
//! use turbo_prehash::{BuildHasherExt, PreHashed};
//! use std::collections::HashMap;
//! use std::hash::{BuildHasherDefault, RandomState, Hash}; //! use std::hash::{BuildHasherDefault, RandomState, Hash};
//! //!
//! use rustc_hash::FxHashMap;
//! use turbo_prehash::{BuildHasherExt, PreHashed};
//!
//! /// hash a key, returning a prehashed value //! /// hash a key, returning a prehashed value
//! fn hash_key<T: Hash>(key: T) -> PreHashed<T> { //! fn hash_key<T: Hash>(key: T) -> PreHashed<T> {
//! RandomState::new().prehash(key) //! RandomState::new().prehash(key)
//! } //! }
//! //!
//! // create hashmap to hold pre-hashed values //! // create hashmap to hold pre-hashed values
//! let mut map: HashMap<PreHashed<String>, String> = Default::default(); //! let mut map: FxHashMap<PreHashed<String>, String> = FxHashMap::default();
//! //!
//! // insert a prehashed value //! // insert a prehashed value
//! let hashed_key = hash_key("hello".to_string()); //! let hashed_key = hash_key("hello".to_string());
......
...@@ -13,6 +13,7 @@ itertools.workspace = true ...@@ -13,6 +13,7 @@ itertools.workspace = true
lsp-server = "0.7.6" lsp-server = "0.7.6"
lsp-types = "0.95.1" lsp-types = "0.95.1"
proc-macro2 = { workspace = true, features = ["span-locations"] } proc-macro2 = { workspace = true, features = ["span-locations"] }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true serde_json.workspace = true
serde_path_to_error = "0.1.16" serde_path_to_error = "0.1.16"
......
use std::{collections::HashMap, fs::OpenOptions, path::PathBuf}; use std::{fs::OpenOptions, path::PathBuf};
use rustc_hash::FxHashMap;
use crate::{lsp_client::RAClient, Identifier, IdentifierReference}; use crate::{lsp_client::RAClient, Identifier, IdentifierReference};
...@@ -7,7 +9,7 @@ use crate::{lsp_client::RAClient, Identifier, IdentifierReference}; ...@@ -7,7 +9,7 @@ use crate::{lsp_client::RAClient, Identifier, IdentifierReference};
/// store. /// store.
pub struct CallResolver<'a> { pub struct CallResolver<'a> {
client: &'a mut RAClient, client: &'a mut RAClient,
state: HashMap<Identifier, Vec<IdentifierReference>>, state: FxHashMap<Identifier, Vec<IdentifierReference>>,
path: Option<PathBuf>, path: Option<PathBuf>,
} }
...@@ -26,7 +28,7 @@ impl Drop for CallResolver<'_> { ...@@ -26,7 +28,7 @@ impl Drop for CallResolver<'_> {
impl<'a> CallResolver<'a> { impl<'a> CallResolver<'a> {
pub fn new(client: &'a mut RAClient, path: Option<PathBuf>) -> Self { pub fn new(client: &'a mut RAClient, path: Option<PathBuf>) -> Self {
// load bincode-encoded HashMap from path // load bincode-encoded FxHashMap from path
let state = path let state = path
.as_ref() .as_ref()
.and_then(|path| { .and_then(|path| {
...@@ -38,7 +40,7 @@ impl<'a> CallResolver<'a> { ...@@ -38,7 +40,7 @@ impl<'a> CallResolver<'a> {
.open(path) .open(path)
.unwrap(); .unwrap();
let reader = std::io::BufReader::new(file); let reader = std::io::BufReader::new(file);
bincode::deserialize_from::<_, HashMap<Identifier, Vec<IdentifierReference>>>( bincode::deserialize_from::<_, FxHashMap<Identifier, Vec<IdentifierReference>>>(
reader, reader,
) )
.inspect_err(|_| { .inspect_err(|_| {
......
use std::{ use std::{
collections::{HashMap, HashSet},
error::Error, error::Error,
fs, fs,
path::PathBuf, path::PathBuf,
...@@ -13,6 +12,7 @@ use call_resolver::CallResolver; ...@@ -13,6 +12,7 @@ use call_resolver::CallResolver;
use clap::Parser; use clap::Parser;
use identifier::{Identifier, IdentifierReference}; use identifier::{Identifier, IdentifierReference};
use itertools::Itertools; use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet};
use syn::visit::Visit; use syn::visit::Visit;
use visitor::CallingStyleVisitor; use visitor::CallingStyleVisitor;
...@@ -75,8 +75,8 @@ fn main() -> Result<(), Box<dyn Error>> { ...@@ -75,8 +75,8 @@ fn main() -> Result<(), Box<dyn Error>> {
/// search the given folders recursively and attempt to find all tasks inside /// search the given folders recursively and attempt to find all tasks inside
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
fn get_all_tasks(folders: &[PathBuf]) -> HashMap<Identifier, Vec<String>> { fn get_all_tasks(folders: &[PathBuf]) -> FxHashMap<Identifier, Vec<String>> {
let mut out = HashMap::new(); let mut out = FxHashMap::default();
for folder in folders { for folder in folders {
let walker = ignore::Walk::new(folder); let walker = ignore::Walk::new(folder);
...@@ -139,18 +139,18 @@ fn get_all_tasks(folders: &[PathBuf]) -> HashMap<Identifier, Vec<String>> { ...@@ -139,18 +139,18 @@ fn get_all_tasks(folders: &[PathBuf]) -> HashMap<Identifier, Vec<String>> {
/// Given a list of tasks, get all the tasks that call that one /// Given a list of tasks, get all the tasks that call that one
fn resolve_tasks( fn resolve_tasks(
tasks: &mut HashMap<Identifier, Vec<String>>, tasks: &mut FxHashMap<Identifier, Vec<String>>,
client: &mut CallResolver, client: &mut CallResolver,
halt: Arc<AtomicBool>, halt: Arc<AtomicBool>,
) -> HashMap<Identifier, Vec<IdentifierReference>> { ) -> FxHashMap<Identifier, Vec<IdentifierReference>> {
tracing::info!( tracing::info!(
"found {} tasks, of which {} cached", "found {} tasks, of which {} cached",
tasks.len(), tasks.len(),
client.cached_count() client.cached_count()
); );
let mut unresolved = tasks.keys().cloned().collect::<HashSet<_>>(); let mut unresolved = tasks.keys().cloned().collect::<FxHashSet<_>>();
let mut resolved = HashMap::new(); let mut resolved = FxHashMap::default();
while let Some(top) = unresolved.iter().next().cloned() { while let Some(top) = unresolved.iter().next().cloned() {
unresolved.remove(&top); unresolved.remove(&top);
...@@ -183,8 +183,8 @@ fn resolve_tasks( ...@@ -183,8 +183,8 @@ fn resolve_tasks(
/// returns a list of pairs with a task, the task that calls it, and the calling /// returns a list of pairs with a task, the task that calls it, and the calling
/// style /// style
fn resolve_concurrency( fn resolve_concurrency(
task_list: &HashMap<Identifier, Vec<String>>, task_list: &FxHashMap<Identifier, Vec<String>>,
dep_tree: &HashMap<Identifier, Vec<IdentifierReference>>, // pairs of tasks and call trees dep_tree: &FxHashMap<Identifier, Vec<IdentifierReference>>, // pairs of tasks and call trees
halt: Arc<AtomicBool>, halt: Arc<AtomicBool>,
) -> Vec<(Identifier, Identifier, CallingStyle)> { ) -> Vec<(Identifier, Identifier, CallingStyle)> {
// println!("{:?}", dep_tree); // println!("{:?}", dep_tree);
...@@ -240,13 +240,13 @@ fn resolve_concurrency( ...@@ -240,13 +240,13 @@ fn resolve_concurrency(
/// Write the dep tree into the given file using cypher syntax /// Write the dep tree into the given file using cypher syntax
fn write_dep_tree( fn write_dep_tree(
task_list: &HashMap<Identifier, Vec<String>>, task_list: &FxHashMap<Identifier, Vec<String>>,
dep_tree: Vec<(Identifier, Identifier, CallingStyle)>, dep_tree: Vec<(Identifier, Identifier, CallingStyle)>,
out: &std::path::Path, out: &std::path::Path,
) { ) {
use std::io::Write; use std::io::Write;
let mut node_ids = HashMap::new(); let mut node_ids = FxHashMap::default();
let mut counter = 0; let mut counter = 0;
let mut file = std::fs::File::create(out).unwrap(); let mut file = std::fs::File::create(out).unwrap();
...@@ -259,7 +259,7 @@ fn write_dep_tree( ...@@ -259,7 +259,7 @@ fn write_dep_tree(
.iter() .iter()
.flat_map(|(dest, src, _)| [(src, &empty), (dest, &empty)]) .flat_map(|(dest, src, _)| [(src, &empty), (dest, &empty)])
.chain(task_list) .chain(task_list)
.collect::<HashMap<_, _>>(); .collect::<FxHashMap<_, _>>();
for (ident, tags) in node_list { for (ident, tags) in node_list {
counter += 1; counter += 1;
......
...@@ -5,7 +5,6 @@ mod storage; ...@@ -5,7 +5,6 @@ mod storage;
use std::{ use std::{
borrow::Cow, borrow::Cow,
collections::{HashMap, HashSet},
future::Future, future::Future,
hash::BuildHasherDefault, hash::BuildHasherDefault,
mem::take, mem::take,
...@@ -20,7 +19,7 @@ use std::{ ...@@ -20,7 +19,7 @@ use std::{
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use auto_hash_map::{AutoMap, AutoSet}; use auto_hash_map::{AutoMap, AutoSet};
use parking_lot::{Condvar, Mutex}; use parking_lot::{Condvar, Mutex};
use rustc_hash::FxHasher; use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
use smallvec::smallvec; use smallvec::smallvec;
use tokio::time::{Duration, Instant}; use tokio::time::{Duration, Instant};
use turbo_tasks::{ use turbo_tasks::{
...@@ -67,14 +66,14 @@ const SNAPSHOT_REQUESTED_BIT: usize = 1 << (usize::BITS - 1); ...@@ -67,14 +66,14 @@ const SNAPSHOT_REQUESTED_BIT: usize = 1 << (usize::BITS - 1);
struct SnapshotRequest { struct SnapshotRequest {
snapshot_requested: bool, snapshot_requested: bool,
suspended_operations: HashSet<PtrEqArc<AnyOperation>>, suspended_operations: FxHashSet<PtrEqArc<AnyOperation>>,
} }
impl SnapshotRequest { impl SnapshotRequest {
fn new() -> Self { fn new() -> Self {
Self { Self {
snapshot_requested: false, snapshot_requested: false,
suspended_operations: HashSet::new(), suspended_operations: FxHashSet::default(),
} }
} }
} }
...@@ -1196,7 +1195,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -1196,7 +1195,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let _ = stateful; let _ = stateful;
// handle cell counters: update max index and remove cells that are no longer used // handle cell counters: update max index and remove cells that are no longer used
let mut old_counters: HashMap<_, _> = let mut old_counters: FxHashMap<_, _> =
get_many!(task, CellTypeMaxIndex { cell_type } max_index => (cell_type, *max_index)); get_many!(task, CellTypeMaxIndex { cell_type } max_index => (cell_type, *max_index));
for (&cell_type, &max_index) in cell_counters.iter() { for (&cell_type, &max_index) in cell_counters.iter() {
if let Some(old_max_index) = old_counters.remove(&cell_type) { if let Some(old_max_index) = old_counters.remove(&cell_type) {
......
...@@ -16,5 +16,6 @@ anyhow = { workspace = true } ...@@ -16,5 +16,6 @@ anyhow = { workspace = true }
cargo-lock = "8.0.2" cargo-lock = "8.0.2"
glob = "0.3.0" glob = "0.3.0"
quote = { workspace = true } quote = { workspace = true }
rustc-hash = { workspace = true }
syn = { workspace = true, features = ["full"] } syn = { workspace = true, features = ["full"] }
turbo-tasks-macros-shared = { workspace = true } turbo-tasks-macros-shared = { workspace = true }
use std::{ use std::{
collections::{HashMap, HashSet},
env::{self, current_dir}, env::{self, current_dir},
fmt::{Display, Write}, fmt::{Display, Write},
fs::read_dir, fs::read_dir,
...@@ -10,6 +9,7 @@ use std::{ ...@@ -10,6 +9,7 @@ use std::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use glob::glob; use glob::glob;
use quote::ToTokens; use quote::ToTokens;
use rustc_hash::{FxHashMap, FxHashSet};
use syn::{ use syn::{
parse_quote, Attribute, Ident, Item, ItemEnum, ItemFn, ItemImpl, ItemMacro, ItemMod, parse_quote, Attribute, Ident, Item, ItemEnum, ItemFn, ItemImpl, ItemMacro, ItemMod,
ItemStruct, ItemTrait, TraitItem, TraitItemMethod, ItemStruct, ItemTrait, TraitItem, TraitItemMethod,
...@@ -98,7 +98,7 @@ pub fn generate_register() { ...@@ -98,7 +98,7 @@ pub fn generate_register() {
let prefix = format!("{crate_name}@{hash}::"); let prefix = format!("{crate_name}@{hash}::");
let mut register_code = String::new(); let mut register_code = String::new();
let mut values = HashMap::new(); let mut values = FxHashMap::default();
let out_file = out_dir.join(filename); let out_file = out_dir.join(filename);
...@@ -184,7 +184,7 @@ pub fn rerun_if_glob(globs: &str, root: &str) { ...@@ -184,7 +184,7 @@ pub fn rerun_if_glob(globs: &str, root: &str) {
let globs = cwd.join(globs.replace('/', PATH_SEP.to_string().as_str())); let globs = cwd.join(globs.replace('/', PATH_SEP.to_string().as_str()));
let root = cwd.join(root.replace('/', PATH_SEP.to_string().as_str())); let root = cwd.join(root.replace('/', PATH_SEP.to_string().as_str()));
println!("cargo:rerun-if-changed={}", root.display()); println!("cargo:rerun-if-changed={}", root.display());
let mut seen = HashSet::from([root]); let mut seen = FxHashSet::from_iter([root]);
for entry in glob(globs.to_str().unwrap()).unwrap() { for entry in glob(globs.to_str().unwrap()).unwrap() {
let path = entry.unwrap(); let path = entry.unwrap();
for ancestor in path.ancestors() { for ancestor in path.ancestors() {
...@@ -225,7 +225,7 @@ struct RegisterContext<'a> { ...@@ -225,7 +225,7 @@ struct RegisterContext<'a> {
prefix: &'a str, prefix: &'a str,
register: &'a mut String, register: &'a mut String,
values: &'a mut HashMap<ValueKey, ValueEntry>, values: &'a mut FxHashMap<ValueKey, ValueEntry>,
} }
impl RegisterContext<'_> { impl RegisterContext<'_> {
......
...@@ -40,6 +40,7 @@ mime = { workspace = true } ...@@ -40,6 +40,7 @@ mime = { workspace = true }
notify = { workspace = true } notify = { workspace = true }
parking_lot = { workspace = true } parking_lot = { workspace = true }
rayon = { workspace = true } rayon = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["rc"] } serde = { workspace = true, features = ["rc"] }
serde_bytes = { workspace = true } serde_bytes = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
......
use std::{ use std::sync::{LockResult, Mutex, MutexGuard};
collections::{HashMap, HashSet},
sync::{LockResult, Mutex, MutexGuard},
};
use concurrent_queue::ConcurrentQueue; use concurrent_queue::ConcurrentQueue;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{de::Visitor, Deserialize, Serialize}; use serde::{de::Visitor, Deserialize, Serialize};
use turbo_tasks::Invalidator; use turbo_tasks::Invalidator;
pub struct InvalidatorMap { pub struct InvalidatorMap {
queue: ConcurrentQueue<(String, Invalidator)>, queue: ConcurrentQueue<(String, Invalidator)>,
map: Mutex<HashMap<String, HashSet<Invalidator>>>, map: Mutex<FxHashMap<String, FxHashSet<Invalidator>>>,
} }
impl Default for InvalidatorMap { impl Default for InvalidatorMap {
...@@ -26,7 +24,7 @@ impl InvalidatorMap { ...@@ -26,7 +24,7 @@ impl InvalidatorMap {
Self::default() Self::default()
} }
pub fn lock(&self) -> LockResult<MutexGuard<'_, HashMap<String, HashSet<Invalidator>>>> { pub fn lock(&self) -> LockResult<MutexGuard<'_, FxHashMap<String, FxHashSet<Invalidator>>>> {
let mut guard = self.map.lock()?; let mut guard = self.map.lock()?;
while let Ok((key, value)) = self.queue.pop() { while let Ok((key, value)) = self.queue.pop() {
guard.entry(key).or_default().insert(value); guard.entry(key).or_default().insert(value);
......
...@@ -27,7 +27,6 @@ mod watcher; ...@@ -27,7 +27,6 @@ mod watcher;
use std::{ use std::{
borrow::Cow, borrow::Cow,
cmp::{min, Ordering}, cmp::{min, Ordering},
collections::HashSet,
fmt::{self, Debug, Display, Formatter, Write as _}, fmt::{self, Debug, Display, Formatter, Write as _},
fs::FileType, fs::FileType,
future::Future, future::Future,
...@@ -50,6 +49,7 @@ use mime::Mime; ...@@ -50,6 +49,7 @@ use mime::Mime;
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon::iter::{IntoParallelIterator, ParallelIterator};
use read_glob::read_glob; use read_glob::read_glob;
pub use read_glob::ReadGlobResult; pub use read_glob::ReadGlobResult;
use rustc_hash::FxHashSet;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use tokio::{ use tokio::{
...@@ -261,9 +261,10 @@ impl DiskFileSystemInner { ...@@ -261,9 +261,10 @@ impl DiskFileSystemInner {
&self, &self,
path: &Path, path: &Path,
invalidator: Invalidator, invalidator: Invalidator,
) -> Result<HashSet<Invalidator>> { ) -> Result<FxHashSet<Invalidator>> {
let mut invalidator_map = self.invalidator_map.lock().unwrap(); let mut invalidator_map = self.invalidator_map.lock().unwrap();
let old_invalidators = invalidator_map.insert(path_to_key(path), [invalidator].into()); let old_invalidators =
invalidator_map.insert(path_to_key(path), FxHashSet::from_iter([invalidator]));
drop(invalidator_map); drop(invalidator_map);
#[cfg(not(any(target_os = "macos", target_os = "windows")))] #[cfg(not(any(target_os = "macos", target_os = "windows")))]
if let Some(dir) = path.parent() { if let Some(dir) = path.parent() {
...@@ -329,7 +330,7 @@ impl DiskFileSystemInner { ...@@ -329,7 +330,7 @@ impl DiskFileSystemInner {
}); });
} }
fn invalidate_from_write(&self, full_path: &Path, invalidators: HashSet<Invalidator>) { fn invalidate_from_write(&self, full_path: &Path, invalidators: FxHashSet<Invalidator>) {
if !invalidators.is_empty() { if !invalidators.is_empty() {
if let Some(path) = format_absolute_fs_path(full_path, &self.name, self.root_path()) { if let Some(path) = format_absolute_fs_path(full_path, &self.name, self.root_path()) {
if invalidators.len() == 1 { if invalidators.len() == 1 {
......
use std::{ use std::{collections::hash_map::Entry, hash::Hash, marker::PhantomData};
collections::{hash_map::Entry, HashMap},
hash::Hash,
marker::PhantomData,
};
use parking_lot::Mutex; use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use turbo_tasks::event::Event; use turbo_tasks::event::Event;
pub struct MutexMap<K> { pub struct MutexMap<K> {
map: Mutex<HashMap<K, Option<(Event, usize)>>>, map: Mutex<FxHashMap<K, Option<(Event, usize)>>>,
} }
impl<K> Default for MutexMap<K> { impl<K> Default for MutexMap<K> {
fn default() -> Self { fn default() -> Self {
Self { Self {
map: Mutex::new(HashMap::new()), map: Mutex::new(FxHashMap::default()),
} }
} }
} }
......
use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
...@@ -9,8 +8,8 @@ use crate::{glob::Glob, DirectoryContent, DirectoryEntry, FileSystemPath}; ...@@ -9,8 +8,8 @@ use crate::{glob::Glob, DirectoryContent, DirectoryEntry, FileSystemPath};
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct ReadGlobResult { pub struct ReadGlobResult {
pub results: HashMap<String, DirectoryEntry>, pub results: FxHashMap<String, DirectoryEntry>,
pub inner: HashMap<String, ResolvedVc<ReadGlobResult>>, pub inner: FxHashMap<String, ResolvedVc<ReadGlobResult>>,
} }
/// Reads matches of a glob pattern. /// Reads matches of a glob pattern.
......
use std::{ use std::{
collections::{HashMap, HashSet},
mem::take, mem::take,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::{ sync::{
...@@ -15,6 +14,7 @@ use notify::{ ...@@ -15,6 +14,7 @@ use notify::{
Config, EventKind, PollWatcher, RecommendedWatcher, RecursiveMode, Watcher, Config, EventKind, PollWatcher, RecommendedWatcher, RecursiveMode, Watcher,
}; };
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::instrument; use tracing::instrument;
use turbo_tasks::{spawn_thread, Invalidator}; use turbo_tasks::{spawn_thread, Invalidator};
...@@ -240,13 +240,13 @@ impl DiskWatcher { ...@@ -240,13 +240,13 @@ impl DiskWatcher {
inner: Arc<DiskFileSystemInner>, inner: Arc<DiskFileSystemInner>,
report_invalidation_reason: bool, report_invalidation_reason: bool,
) { ) {
let mut batched_invalidate_path = HashSet::new(); let mut batched_invalidate_path = FxHashSet::default();
let mut batched_invalidate_path_dir = HashSet::new(); let mut batched_invalidate_path_dir = FxHashSet::default();
let mut batched_invalidate_path_and_children = HashSet::new(); let mut batched_invalidate_path_and_children = FxHashSet::default();
let mut batched_invalidate_path_and_children_dir = HashSet::new(); let mut batched_invalidate_path_and_children_dir = FxHashSet::default();
#[cfg(not(any(target_os = "macos", target_os = "windows")))] #[cfg(not(any(target_os = "macos", target_os = "windows")))]
let mut batched_new_paths = HashSet::new(); let mut batched_new_paths = FxHashSet::default();
'outer: loop { 'outer: loop {
let mut event = rx.recv().or(Err(TryRecvError::Disconnected)); let mut event = rx.recv().or(Err(TryRecvError::Disconnected));
...@@ -459,7 +459,7 @@ fn invalidate( ...@@ -459,7 +459,7 @@ fn invalidate(
fn invalidate_path( fn invalidate_path(
inner: &DiskFileSystemInner, inner: &DiskFileSystemInner,
report_invalidation_reason: bool, report_invalidation_reason: bool,
invalidator_map: &mut HashMap<String, HashSet<Invalidator>>, invalidator_map: &mut FxHashMap<String, FxHashSet<Invalidator>>,
paths: impl Iterator<Item = PathBuf>, paths: impl Iterator<Item = PathBuf>,
) { ) {
for path in paths { for path in paths {
...@@ -475,7 +475,7 @@ fn invalidate_path( ...@@ -475,7 +475,7 @@ fn invalidate_path(
fn invalidate_path_and_children_execute( fn invalidate_path_and_children_execute(
inner: &DiskFileSystemInner, inner: &DiskFileSystemInner,
report_invalidation_reason: bool, report_invalidation_reason: bool,
invalidator_map: &mut HashMap<String, HashSet<Invalidator>>, invalidator_map: &mut FxHashMap<String, FxHashSet<Invalidator>>,
paths: impl Iterator<Item = PathBuf>, paths: impl Iterator<Item = PathBuf>,
) { ) {
for path in paths { for path in paths {
......
...@@ -18,5 +18,6 @@ proc-macro-error = "1.0.4" ...@@ -18,5 +18,6 @@ proc-macro-error = "1.0.4"
proc-macro2 = { workspace = true } proc-macro2 = { workspace = true }
quote = { workspace = true } quote = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true }
syn = { workspace = true, features = ["full", "extra-traits", "visit-mut"] } syn = { workspace = true, features = ["full", "extra-traits", "visit-mut"] }
turbo-tasks-macros-shared = { workspace = true } turbo-tasks-macros-shared = { workspace = true }
use std::{borrow::Cow, collections::HashSet}; use std::borrow::Cow;
use proc_macro2::{Ident, Span, TokenStream}; use proc_macro2::{Ident, Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens}; use quote::{quote, quote_spanned, ToTokens};
use rustc_hash::FxHashSet;
use syn::{ use syn::{
parenthesized, parenthesized,
parse::{Parse, ParseStream}, parse::{Parse, ParseStream},
...@@ -753,7 +754,7 @@ pub struct FunctionArguments { ...@@ -753,7 +754,7 @@ pub struct FunctionArguments {
/// ///
/// This should only be used by the task that directly performs the IO. Tasks that transitively /// This should only be used by the task that directly performs the IO. Tasks that transitively
/// perform IO should not be manually annotated. /// perform IO should not be manually annotated.
io_markers: HashSet<IoMarker>, io_markers: FxHashSet<IoMarker>,
/// Should the function return an `OperationVc` instead of a `Vc`? Also ensures that all /// Should the function return an `OperationVc` instead of a `Vc`? Also ensures that all
/// arguments are `OperationValue`s. Mutually exclusive with the `local_cells` flag. /// arguments are `OperationValue`s. Mutually exclusive with the `local_cells` flag.
/// ///
......
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote; use quote::quote;
use rustc_hash::FxHashSet;
use syn::{parse_macro_input, spanned::Spanned, visit_mut::VisitMut, GenericParam, Lifetime, Type}; use syn::{parse_macro_input, spanned::Spanned, visit_mut::VisitMut, GenericParam, Lifetime, Type};
use turbo_tasks_macros_shared::{get_type_ident, GenericTypeInput}; use turbo_tasks_macros_shared::{get_type_ident, GenericTypeInput};
...@@ -105,7 +106,7 @@ pub fn generic_type(input: TokenStream) -> TokenStream { ...@@ -105,7 +106,7 @@ pub fn generic_type(input: TokenStream) -> TokenStream {
} }
struct ReplaceGenericsVisitor<'a> { struct ReplaceGenericsVisitor<'a> {
generics: &'a std::collections::HashSet<String>, generics: &'a FxHashSet<String>,
} }
impl VisitMut for ReplaceGenericsVisitor<'_> { impl VisitMut for ReplaceGenericsVisitor<'_> {
...@@ -134,7 +135,7 @@ fn replace_generics_with_unit<'a, P>(params: P, ty: &Type) -> Type ...@@ -134,7 +135,7 @@ fn replace_generics_with_unit<'a, P>(params: P, ty: &Type) -> Type
where where
P: IntoIterator<Item = &'a GenericParam>, P: IntoIterator<Item = &'a GenericParam>,
{ {
let generics_set: std::collections::HashSet<_> = params let generics_set: FxHashSet<_> = params
.into_iter() .into_iter()
.filter_map(|param| { .filter_map(|param| {
if let GenericParam::Type(type_param) = param { if let GenericParam::Type(type_param) = param {
......
use std::{ use std::{
collections::HashSet,
fmt::Debug, fmt::Debug,
hash::Hash, hash::Hash,
iter::once, iter::once,
...@@ -15,6 +14,7 @@ use parking_lot::{Mutex, MutexGuard}; ...@@ -15,6 +14,7 @@ use parking_lot::{Mutex, MutexGuard};
use rand::{rngs::SmallRng, Rng, SeedableRng}; use rand::{rngs::SmallRng, Rng, SeedableRng};
use ref_cast::RefCast; use ref_cast::RefCast;
use rstest::*; use rstest::*;
use rustc_hash::FxHashSet;
use turbo_tasks::FxIndexSet; use turbo_tasks::FxIndexSet;
use self::aggregation_data::prepare_aggregation_data; use self::aggregation_data::prepare_aggregation_data;
...@@ -42,7 +42,7 @@ fn check_invariants(ctx: &NodeAggregationContext<'_>, node_ids: impl IntoIterato ...@@ -42,7 +42,7 @@ fn check_invariants(ctx: &NodeAggregationContext<'_>, node_ids: impl IntoIterato
let mut queue = node_ids.into_iter().collect::<Vec<_>>(); let mut queue = node_ids.into_iter().collect::<Vec<_>>();
// print(ctx, &queue[0], true); // print(ctx, &queue[0], true);
#[allow(clippy::mutable_key_type, reason = "this is a test")] #[allow(clippy::mutable_key_type, reason = "this is a test")]
let mut visited = HashSet::new(); let mut visited = FxHashSet::default();
while let Some(node_id) = queue.pop() { while let Some(node_id) = queue.pop() {
assert_eq!(node_id.0.atomic.load(Ordering::SeqCst), 0); assert_eq!(node_id.0.atomic.load(Ordering::SeqCst), 0);
let node = ctx.node(&node_id); let node = ctx.node(&node_id);
...@@ -165,7 +165,7 @@ fn print_graph<C: AggregationContext>( ...@@ -165,7 +165,7 @@ fn print_graph<C: AggregationContext>(
name_fn: impl Fn(&C::NodeRef) -> String, name_fn: impl Fn(&C::NodeRef) -> String,
) { ) {
let mut queue = entries.into_iter().collect::<Vec<_>>(); let mut queue = entries.into_iter().collect::<Vec<_>>();
let mut visited = queue.iter().cloned().collect::<HashSet<_>>(); let mut visited = queue.iter().cloned().collect::<FxHashSet<_>>();
while let Some(node_id) = queue.pop() { while let Some(node_id) = queue.pop() {
let name = name_fn(&node_id); let name = name_fn(&node_id);
let node = ctx.node(&node_id); let node = ctx.node(&node_id);
......
...@@ -5,7 +5,6 @@ mod run; ...@@ -5,7 +5,6 @@ mod run;
use std::{ use std::{
borrow::Cow, borrow::Cow,
collections::HashMap,
future::Future, future::Future,
mem::replace, mem::replace,
panic::AssertUnwindSafe, panic::AssertUnwindSafe,
...@@ -14,6 +13,7 @@ use std::{ ...@@ -14,6 +13,7 @@ use std::{
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use futures::FutureExt; use futures::FutureExt;
use rustc_hash::FxHashMap;
use turbo_tasks::{ use turbo_tasks::{
backend::{CellContent, TaskCollectiblesMap, TypedCellContent}, backend::{CellContent, TaskCollectiblesMap, TypedCellContent},
event::{Event, EventListener}, event::{Event, EventListener},
...@@ -34,7 +34,7 @@ enum Task { ...@@ -34,7 +34,7 @@ enum Task {
#[derive(Default)] #[derive(Default)]
pub struct VcStorage { pub struct VcStorage {
this: Weak<Self>, this: Weak<Self>,
cells: Mutex<HashMap<(TaskId, CellId), CellContent>>, cells: Mutex<FxHashMap<(TaskId, CellId), CellContent>>,
tasks: Mutex<Vec<Task>>, tasks: Mutex<Vec<Task>>,
} }
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
#![feature(arbitrary_self_types_pointers)] #![feature(arbitrary_self_types_pointers)]
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this #![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this
use std::{collections::HashSet, time::Duration}; use std::time::Duration;
use anyhow::Result; use anyhow::Result;
use auto_hash_map::AutoSet; use auto_hash_map::AutoSet;
use rustc_hash::FxHashSet;
use tokio::time::sleep; use tokio::time::sleep;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{emit, CollectiblesSource, ResolvedVc, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{emit, CollectiblesSource, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
...@@ -20,7 +21,7 @@ async fn transitive_emitting() { ...@@ -20,7 +21,7 @@ async fn transitive_emitting() {
let result_val = result_op.connect().strongly_consistent().await?; let result_val = result_op.connect().strongly_consistent().await?;
let list = result_op.peek_collectibles::<Box<dyn ValueToString>>(); let list = result_op.peek_collectibles::<Box<dyn ValueToString>>();
assert_eq!(list.len(), 2); assert_eq!(list.len(), 2);
let mut expected = ["123", "42"].into_iter().collect::<HashSet<_>>(); let mut expected = ["123", "42"].into_iter().collect::<FxHashSet<_>>();
for collectible in list { for collectible in list {
assert!(expected.remove(collectible.to_string().await?.as_str())) assert!(expected.remove(collectible.to_string().await?.as_str()))
} }
...@@ -38,7 +39,7 @@ async fn transitive_emitting_indirect() { ...@@ -38,7 +39,7 @@ async fn transitive_emitting_indirect() {
let collectibles_op = my_transitive_emitting_function_collectibles("".into(), "".into()); let collectibles_op = my_transitive_emitting_function_collectibles("".into(), "".into());
let list = collectibles_op.connect().strongly_consistent().await?; let list = collectibles_op.connect().strongly_consistent().await?;
assert_eq!(list.len(), 2); assert_eq!(list.len(), 2);
let mut expected = ["123", "42"].into_iter().collect::<HashSet<_>>(); let mut expected = ["123", "42"].into_iter().collect::<FxHashSet<_>>();
for collectible in list.iter() { for collectible in list.iter() {
assert!(expected.remove(collectible.to_string().await?.as_str())) assert!(expected.remove(collectible.to_string().await?.as_str()))
} }
...@@ -56,7 +57,7 @@ async fn multi_emitting() { ...@@ -56,7 +57,7 @@ async fn multi_emitting() {
let result_val = result_op.connect().strongly_consistent().await?; let result_val = result_op.connect().strongly_consistent().await?;
let list = result_op.peek_collectibles::<Box<dyn ValueToString>>(); let list = result_op.peek_collectibles::<Box<dyn ValueToString>>();
assert_eq!(list.len(), 2); assert_eq!(list.len(), 2);
let mut expected = ["123", "42"].into_iter().collect::<HashSet<_>>(); let mut expected = ["123", "42"].into_iter().collect::<FxHashSet<_>>();
for collectible in list { for collectible in list {
assert!(expected.remove(collectible.to_string().await?.as_str())) assert!(expected.remove(collectible.to_string().await?.as_str()))
} }
......
...@@ -188,7 +188,7 @@ where ...@@ -188,7 +188,7 @@ where
} }
} }
impl<K, V> ValueDebugFormat for std::collections::HashMap<K, V> impl<K, V, S> ValueDebugFormat for std::collections::HashMap<K, V, S>
where where
K: Debug, K: Debug,
V: ValueDebugFormat, V: ValueDebugFormat,
......
use std::{borrow::Cow, collections::HashSet, future::Future, mem::replace, panic, pin::Pin}; use std::{borrow::Cow, future::Future, mem::replace, panic, pin::Pin};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use auto_hash_map::AutoSet; use auto_hash_map::AutoSet;
use parking_lot::Mutex; use parking_lot::Mutex;
use rustc_hash::FxHashSet;
use tracing::{Instrument, Span}; use tracing::{Instrument, Span};
use crate::{ use crate::{
...@@ -233,7 +234,7 @@ impl PartialEq for Effects { ...@@ -233,7 +234,7 @@ impl PartialEq for Effects {
.effects .effects
.iter() .iter()
.map(ReadRef::ptr) .map(ReadRef::ptr)
.collect::<HashSet<_>>(); .collect::<FxHashSet<_>>();
other other
.effects .effects
.iter() .iter()
......
use std::{ use std::{collections::VecDeque, hash::Hash};
collections::{HashSet, VecDeque},
hash::Hash,
};
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
...@@ -102,7 +99,7 @@ where ...@@ -102,7 +99,7 @@ where
.rev() .rev()
.map(|root| (ReverseTopologicalPass::Pre, root)) .map(|root| (ReverseTopologicalPass::Pre, root))
.collect(), .collect(),
visited: HashSet::new(), visited: FxHashSet::default(),
} }
} }
...@@ -164,7 +161,7 @@ where ...@@ -164,7 +161,7 @@ where
{ {
adjacency_map: FxHashMap<T, Vec<T>>, adjacency_map: FxHashMap<T, Vec<T>>,
stack: Vec<(ReverseTopologicalPass, T)>, stack: Vec<(ReverseTopologicalPass, T)>,
visited: HashSet<T>, visited: FxHashSet<T>,
} }
impl<T> Iterator for IntoReverseTopologicalIter<T> impl<T> Iterator for IntoReverseTopologicalIter<T>
......
use std::{collections::HashSet, hash::Hash}; use std::hash::Hash;
use rustc_hash::FxHashSet;
use super::VisitedNodes; use super::VisitedNodes;
...@@ -53,7 +55,7 @@ where ...@@ -53,7 +55,7 @@ where
StoreImpl: GraphStore, StoreImpl: GraphStore,
{ {
store: StoreImpl, store: StoreImpl,
visited: HashSet<StoreImpl::Node>, visited: FxHashSet<StoreImpl::Node>,
} }
impl<StoreImpl> SkipDuplicates<StoreImpl> impl<StoreImpl> SkipDuplicates<StoreImpl>
...@@ -63,11 +65,11 @@ where ...@@ -63,11 +65,11 @@ where
pub fn new(store: StoreImpl) -> Self { pub fn new(store: StoreImpl) -> Self {
Self { Self {
store, store,
visited: Default::default(), visited: FxHashSet::default(),
} }
} }
pub fn new_with_visited_nodes(store: StoreImpl, visited: HashSet<StoreImpl::Node>) -> Self { pub fn new_with_visited_nodes(store: StoreImpl, visited: FxHashSet<StoreImpl::Node>) -> Self {
Self { store, visited } Self { store, visited }
} }
} }
......
use std::{collections::HashSet, future::Future}; use std::future::Future;
use anyhow::Result; use anyhow::Result;
use futures::{stream::FuturesUnordered, StreamExt}; use futures::{stream::FuturesUnordered, StreamExt};
use rustc_hash::FxHashSet;
use super::{ use super::{
graph_store::{GraphNode, GraphStore}, graph_store::{GraphNode, GraphStore},
...@@ -11,7 +12,7 @@ use super::{ ...@@ -11,7 +12,7 @@ use super::{
/// A list of modules that were already visited and should be skipped (including their subgraphs). /// A list of modules that were already visited and should be skipped (including their subgraphs).
#[derive(Clone, Default, Debug)] #[derive(Clone, Default, Debug)]
pub struct VisitedNodes<T>(pub HashSet<T>); pub struct VisitedNodes<T>(pub FxHashSet<T>);
/// [`GraphTraversal`] is a utility type that can be used to traverse a graph of /// [`GraphTraversal`] is a utility type that can be used to traverse a graph of
/// nodes, where each node can have a variable number of outgoing edges. /// nodes, where each node can have a variable number of outgoing edges.
......
...@@ -29,6 +29,7 @@ parking_lot = { workspace = true } ...@@ -29,6 +29,7 @@ parking_lot = { workspace = true }
portpicker = "0.1.1" portpicker = "0.1.1"
rand = { workspace = true } rand = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tempfile = { workspace = true } tempfile = { workspace = true }
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
......
use std::{collections::HashMap, path::PathBuf}; use std::path::PathBuf;
use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng}; use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng};
use rustc_hash::FxHashMap;
/// Picks modules at random, but with a fixed seed so runs are somewhat /// Picks modules at random, but with a fixed seed so runs are somewhat
/// reproducible. /// reproducible.
...@@ -9,7 +10,7 @@ use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng}; ...@@ -9,7 +10,7 @@ use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng};
/// the same sequence in different samples. /// the same sequence in different samples.
pub struct ModulePicker { pub struct ModulePicker {
depths: Vec<usize>, depths: Vec<usize>,
modules_by_depth: HashMap<usize, Vec<PathBuf>>, modules_by_depth: FxHashMap<usize, Vec<PathBuf>>,
rng: parking_lot::Mutex<StdRng>, rng: parking_lot::Mutex<StdRng>,
} }
...@@ -21,7 +22,7 @@ impl ModulePicker { ...@@ -21,7 +22,7 @@ impl ModulePicker {
// Ensure the module order is deterministic. // Ensure the module order is deterministic.
modules.sort(); modules.sort();
let mut modules_by_depth: HashMap<_, Vec<_>> = HashMap::new(); let mut modules_by_depth: FxHashMap<_, Vec<_>> = FxHashMap::default();
for (module, depth) in modules { for (module, depth) in modules {
modules_by_depth.entry(depth).or_default().push(module); modules_by_depth.entry(depth).or_default().push(module);
} }
......
...@@ -19,6 +19,7 @@ anyhow = { workspace = true } ...@@ -19,6 +19,7 @@ anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] } clap = { workspace = true, features = ["derive"] }
crossterm = "0.26.0" crossterm = "0.26.0"
owo-colors = { workspace = true } owo-colors = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true } turbo-tasks-fs = { workspace = true }
......
use std::{ use std::{
borrow::Cow, borrow::Cow,
cmp::min, cmp::min,
collections::{hash_map::Entry, HashMap, HashSet}, collections::hash_map::Entry,
fmt::Write as _, fmt::Write as _,
path::{Path, PathBuf}, path::{Path, PathBuf},
str::FromStr, str::FromStr,
...@@ -11,6 +11,7 @@ use std::{ ...@@ -11,6 +11,7 @@ use std::{
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use crossterm::style::{StyledContent, Stylize}; use crossterm::style::{StyledContent, Stylize};
use owo_colors::{OwoColorize as _, Style}; use owo_colors::{OwoColorize as _, Style};
use rustc_hash::{FxHashMap, FxHashSet};
use turbo_tasks::{RawVc, ReadRef, TransientInstance, TransientValue, TryJoinIterExt, Vc}; use turbo_tasks::{RawVc, ReadRef, TransientInstance, TransientValue, TryJoinIterExt, Vc};
use turbo_tasks_fs::{source_context::get_source_context, FileLinesContent}; use turbo_tasks_fs::{source_context::get_source_context, FileLinesContent};
use turbopack_core::issue::{ use turbopack_core::issue::{
...@@ -186,7 +187,8 @@ pub fn format_issue( ...@@ -186,7 +187,8 @@ pub fn format_issue(
issue_text issue_text
} }
pub type GroupedIssues = HashMap<IssueSeverity, HashMap<String, HashMap<String, Vec<String>>>>; pub type GroupedIssues =
FxHashMap<IssueSeverity, FxHashMap<String, FxHashMap<String, Vec<String>>>>;
const DEFAULT_SHOW_COUNT: usize = 3; const DEFAULT_SHOW_COUNT: usize = 3;
...@@ -231,13 +233,13 @@ pub struct LogOptions { ...@@ -231,13 +233,13 @@ pub struct LogOptions {
struct SeenIssues { struct SeenIssues {
/// Keeps track of all issue pulled from the source. Used so that we can /// Keeps track of all issue pulled from the source. Used so that we can
/// decrement issues that are not pulled in the current synchronization. /// decrement issues that are not pulled in the current synchronization.
source_to_issue_ids: HashMap<RawVc, HashSet<u64>>, source_to_issue_ids: FxHashMap<RawVc, FxHashSet<u64>>,
/// Counts the number of times a particular issue is seen across all /// Counts the number of times a particular issue is seen across all
/// sources. As long as the count is positive, an issue is considered /// sources. As long as the count is positive, an issue is considered
/// "seen" and will not be relogged. Once the count reaches zero, the /// "seen" and will not be relogged. Once the count reaches zero, the
/// issue is removed and the next time its seen it will be considered new. /// issue is removed and the next time its seen it will be considered new.
issues_count: HashMap<u64, usize>, issues_count: FxHashMap<u64, usize>,
} }
impl SeenIssues { impl SeenIssues {
...@@ -247,7 +249,7 @@ impl SeenIssues { ...@@ -247,7 +249,7 @@ impl SeenIssues {
/// Synchronizes state between the issues previously pulled from this /// Synchronizes state between the issues previously pulled from this
/// source, to the issues now pulled. /// source, to the issues now pulled.
fn new_ids(&mut self, source: RawVc, issue_ids: HashSet<u64>) -> HashSet<u64> { fn new_ids(&mut self, source: RawVc, issue_ids: FxHashSet<u64>) -> FxHashSet<u64> {
let old = self.source_to_issue_ids.entry(source).or_default(); let old = self.source_to_issue_ids.entry(source).or_default();
// difference is the issues that were never counted before. // difference is the issues that were never counted before.
...@@ -274,7 +276,7 @@ impl SeenIssues { ...@@ -274,7 +276,7 @@ impl SeenIssues {
} }
}) })
.cloned() .cloned()
.collect::<HashSet<_>>(); .collect::<FxHashSet<_>>();
// Old now contains only the ids that were not present in the new issue_ids. // Old now contains only the ids that were not present in the new issue_ids.
for id in old.iter() { for id in old.iter() {
...@@ -350,7 +352,7 @@ impl IssueReporter for ConsoleUi { ...@@ -350,7 +352,7 @@ impl IssueReporter for ConsoleUi {
log_level, log_level,
.. ..
} = self.options; } = self.options;
let mut grouped_issues: GroupedIssues = HashMap::new(); let mut grouped_issues: GroupedIssues = FxHashMap::default();
let issues = issues let issues = issues
.iter_with_shortest_path() .iter_with_shortest_path()
...@@ -362,7 +364,7 @@ impl IssueReporter for ConsoleUi { ...@@ -362,7 +364,7 @@ impl IssueReporter for ConsoleUi {
.try_join() .try_join()
.await?; .await?;
let issue_ids = issues.iter().map(|(_, id)| *id).collect::<HashSet<_>>(); let issue_ids = issues.iter().map(|(_, id)| *id).collect::<FxHashSet<_>>();
let mut new_ids = self let mut new_ids = self
.seen .seen
.lock() .lock()
......
...@@ -40,8 +40,10 @@ dunce = { workspace = true } ...@@ -40,8 +40,10 @@ dunce = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
mime = { workspace = true } mime = { workspace = true }
owo-colors = { workspace = true } owo-colors = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] } tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
...@@ -54,7 +56,6 @@ turbopack = { workspace = true } ...@@ -54,7 +56,6 @@ turbopack = { workspace = true }
turbopack-browser = { workspace = true } turbopack-browser = { workspace = true }
turbopack-cli-utils = { workspace = true } turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
tracing = { workspace = true }
turbopack-dev-server = { workspace = true } turbopack-dev-server = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, features = [ turbopack-ecmascript-plugins = { workspace = true, features = [
"transform_emotion", "transform_emotion",
......
use std::{ use std::{
collections::HashSet,
env::current_dir, env::current_dir,
mem::forget, mem::forget,
path::{PathBuf, MAIN_SEPARATOR}, path::{PathBuf, MAIN_SEPARATOR},
...@@ -7,6 +6,7 @@ use std::{ ...@@ -7,6 +6,7 @@ use std::{
}; };
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use rustc_hash::FxHashSet;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
apply_effects, ReadConsistency, ResolvedVc, TransientInstance, TryJoinIterExt, TurboTasks, apply_effects, ReadConsistency, ResolvedVc, TransientInstance, TryJoinIterExt, TurboTasks,
...@@ -438,7 +438,7 @@ async fn build_internal( ...@@ -438,7 +438,7 @@ async fn build_internal(
.try_join() .try_join()
.await?; .await?;
let mut chunks: HashSet<ResolvedVc<Box<dyn OutputAsset>>> = HashSet::new(); let mut chunks: FxHashSet<ResolvedVc<Box<dyn OutputAsset>>> = FxHashSet::default();
for chunk_group in entry_chunk_groups { for chunk_group in entry_chunk_groups {
chunks.extend(&*all_assets_from_entries(*chunk_group).await?); chunks.extend(&*all_assets_from_entries(*chunk_group).await?);
} }
......
use std::{ use std::{
collections::HashSet,
env::current_dir, env::current_dir,
future::{join, Future}, future::{join, Future},
io::{stdout, Write}, io::{stdout, Write},
...@@ -11,6 +10,7 @@ use std::{ ...@@ -11,6 +10,7 @@ use std::{
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use rustc_hash::FxHashSet;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
util::{FormatBytes, FormatDuration}, util::{FormatBytes, FormatDuration},
...@@ -331,7 +331,7 @@ async fn source( ...@@ -331,7 +331,7 @@ async fn source(
.await?; .await?;
let introspect = ResolvedVc::upcast( let introspect = ResolvedVc::upcast(
IntrospectionSource { IntrospectionSource {
roots: HashSet::from([ResolvedVc::upcast(main_source)]), roots: FxHashSet::from_iter([ResolvedVc::upcast(main_source)]),
} }
.resolved_cell(), .resolved_cell(),
); );
......
use std::{ use std::{
collections::{hash_map::Entry, BinaryHeap, HashMap, HashSet}, collections::{hash_map::Entry, BinaryHeap},
hash::Hash, hash::Hash,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
}; };
...@@ -8,6 +8,7 @@ use anyhow::Result; ...@@ -8,6 +8,7 @@ use anyhow::Result;
use either::Either; use either::Either;
use petgraph::graph::{DiGraph, EdgeIndex, NodeIndex}; use petgraph::graph::{DiGraph, EdgeIndex, NodeIndex};
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -76,7 +77,7 @@ impl Hash for RoaringBitmapWrapper { ...@@ -76,7 +77,7 @@ impl Hash for RoaringBitmapWrapper {
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct ChunkGroupInfo(HashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper>); pub struct ChunkGroupInfo(FxHashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper>);
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum ChunkGroup { enum ChunkGroup {
...@@ -164,18 +165,18 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -164,18 +165,18 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
let span = span_outer.clone(); let span = span_outer.clone();
async move { async move {
let mut next_chunk_group_id = 0u32; let mut next_chunk_group_id = 0u32;
let mut chunk_groups_to_id: HashMap<ChunkGroup, ChunkGroupId> = HashMap::new(); let mut chunk_groups_to_id: FxHashMap<ChunkGroup, ChunkGroupId> = FxHashMap::default();
let mut chunk_groups_from_id: HashMap<ChunkGroupId, ChunkGroup> = HashMap::new(); let mut chunk_groups_from_id: FxHashMap<ChunkGroupId, ChunkGroup> = FxHashMap::default();
let mut module_chunk_groups: HashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper> = let mut module_chunk_groups: FxHashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper> =
HashMap::new(); FxHashMap::default();
let graphs = graph.graphs.iter().try_join().await?; let graphs = graph.graphs.iter().try_join().await?;
let module_count = graphs.iter().map(|g| g.graph.node_count()).sum::<usize>(); let module_count = graphs.iter().map(|g| g.graph.node_count()).sum::<usize>();
span.record("module_count", module_count); span.record("module_count", module_count);
// First, compute the depth for each module in the graph // First, compute the depth for each module in the graph
let mut module_depth: HashMap<ResolvedVc<Box<dyn Module>>, usize> = HashMap::new(); let mut module_depth: FxHashMap<ResolvedVc<Box<dyn Module>>, usize> = FxHashMap::default();
// use all entries from all graphs // use all entries from all graphs
let entries = graphs let entries = graphs
.iter() .iter()
...@@ -202,7 +203,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -202,7 +203,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
let mut visitor = let mut visitor =
|parent_info: Option<(&'_ SingleModuleGraphModuleNode, &'_ ChunkingType)>, |parent_info: Option<(&'_ SingleModuleGraphModuleNode, &'_ ChunkingType)>,
node: &'_ SingleModuleGraphModuleNode, node: &'_ SingleModuleGraphModuleNode,
module_chunk_groups: &mut HashMap< module_chunk_groups: &mut FxHashMap<
ResolvedVc<Box<dyn Module>>, ResolvedVc<Box<dyn Module>>,
RoaringBitmapWrapper, RoaringBitmapWrapper,
>| >|
...@@ -316,7 +317,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -316,7 +317,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
let mut visit_count = 0usize; let mut visit_count = 0usize;
{ {
let mut queue_set = HashSet::new(); let mut queue_set = FxHashSet::default();
let mut queue = BinaryHeap::with_capacity(entries.len()); let mut queue = BinaryHeap::with_capacity(entries.len());
for e in entries { for e in entries {
queue.push(NodeWithPriority { queue.push(NodeWithPriority {
......
use std::{ use std::{
borrow::Cow, borrow::Cow,
collections::{BTreeMap, HashMap, HashSet}, collections::BTreeMap,
fmt::{Display, Formatter, Write}, fmt::{Display, Formatter, Write},
future::Future, future::Future,
iter::once, iter::once,
}; };
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{Instrument, Level}; use tracing::{Instrument, Level};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -217,7 +218,7 @@ impl ModuleResolveResult { ...@@ -217,7 +218,7 @@ impl ModuleResolveResult {
.affecting_sources .affecting_sources
.iter() .iter()
.copied() .copied()
.collect::<HashSet<_>>(); .collect::<FxHashSet<_>>();
self.affecting_sources.extend( self.affecting_sources.extend(
other other
.affecting_sources .affecting_sources
...@@ -639,7 +640,7 @@ impl ResolveResult { ...@@ -639,7 +640,7 @@ impl ResolveResult {
.affecting_sources .affecting_sources
.iter() .iter()
.copied() .copied()
.collect::<HashSet<_>>(); .collect::<FxHashSet<_>>();
self.affecting_sources.extend( self.affecting_sources.extend(
other other
.affecting_sources .affecting_sources
...@@ -2795,7 +2796,7 @@ async fn handle_exports_imports_field( ...@@ -2795,7 +2796,7 @@ async fn handle_exports_imports_field(
query: Vc<RcStr>, query: Vc<RcStr>,
) -> Result<Vc<ResolveResult>> { ) -> Result<Vc<ResolveResult>> {
let mut results = Vec::new(); let mut results = Vec::new();
let mut conditions_state = HashMap::new(); let mut conditions_state = FxHashMap::default();
let query_str = query.await?; let query_str = query.await?;
let req = Pattern::Constant(format!("{}{}", path, query_str).into()); let req = Pattern::Constant(format!("{}{}", path, query_str).into());
......
use std::collections::HashSet;
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashSet;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, Vc}; use turbo_tasks::{ResolvedVc, Value, Vc};
use turbo_tasks_fs::{glob::Glob, FileSystemPath}; use turbo_tasks_fs::{glob::Glob, FileSystemPath};
...@@ -45,7 +44,7 @@ impl AfterResolvePluginCondition { ...@@ -45,7 +44,7 @@ impl AfterResolvePluginCondition {
#[turbo_tasks::value] #[turbo_tasks::value]
pub enum BeforeResolvePluginCondition { pub enum BeforeResolvePluginCondition {
Request(ResolvedVc<Glob>), Request(ResolvedVc<Glob>),
Modules(HashSet<RcStr>), Modules(FxHashSet<RcStr>),
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
use std::{ use std::{collections::BTreeMap, fmt::Display, ops::Deref};
collections::{BTreeMap, HashMap},
fmt::Display,
ops::Deref,
};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -127,7 +124,7 @@ impl SubpathValue { ...@@ -127,7 +124,7 @@ impl SubpathValue {
&'a self, &'a self,
conditions: &BTreeMap<RcStr, ConditionValue>, conditions: &BTreeMap<RcStr, ConditionValue>,
unspecified_condition: &ConditionValue, unspecified_condition: &ConditionValue,
condition_overrides: &mut HashMap<&'a str, ConditionValue>, condition_overrides: &mut FxHashMap<&'a str, ConditionValue>,
target: &mut Vec<(&'a str, Vec<(&'a str, bool)>)>, target: &mut Vec<(&'a str, Vec<(&'a str, bool)>)>,
) -> bool { ) -> bool {
match self { match self {
...@@ -242,7 +239,7 @@ impl ReplacedSubpathValue { ...@@ -242,7 +239,7 @@ impl ReplacedSubpathValue {
&'a self, &'a self,
conditions: &BTreeMap<RcStr, ConditionValue>, conditions: &BTreeMap<RcStr, ConditionValue>,
unspecified_condition: &ConditionValue, unspecified_condition: &ConditionValue,
condition_overrides: &mut HashMap<&'a str, ConditionValue>, condition_overrides: &mut FxHashMap<&'a str, ConditionValue>,
target: &mut Vec<(&'a Pattern, Vec<(&'a str, bool)>)>, target: &mut Vec<(&'a Pattern, Vec<(&'a str, bool)>)>,
) -> bool { ) -> bool {
match self { match self {
......
...@@ -19,10 +19,16 @@ indoc = { workspace = true } ...@@ -19,10 +19,16 @@ indoc = { workspace = true }
lightningcss = { workspace = true } lightningcss = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
parcel_selectors = { workspace = true } parcel_selectors = { workspace = true }
parcel_sourcemap = "2.1.1"
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
urlencoding = { workspace = true } smallvec = { workspace = true }
swc_core = { workspace = true, features = [
"ecma_ast",
"common",
"common_concurrent",
] }
tracing = { workspace = true } tracing = { workspace = true }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
...@@ -31,14 +37,7 @@ turbo-tasks-hash = { workspace = true } ...@@ -31,14 +37,7 @@ turbo-tasks-hash = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
turbopack-ecmascript = { workspace = true } turbopack-ecmascript = { workspace = true }
turbopack-swc-utils = { workspace = true } turbopack-swc-utils = { workspace = true }
urlencoding = { workspace = true }
parcel_sourcemap = "2.1.1"
smallvec = { workspace = true }
swc_core = { workspace = true, features = [
"ecma_ast",
"common",
"common_concurrent",
] }
[build-dependencies] [build-dependencies]
turbo-tasks-build = { workspace = true } turbo-tasks-build = { workspace = true }
use std::{ use std::sync::{Arc, RwLock};
collections::HashMap,
sync::{Arc, RwLock},
};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use lightningcss::{ use lightningcss::{
...@@ -12,6 +9,7 @@ use lightningcss::{ ...@@ -12,6 +9,7 @@ use lightningcss::{
visit_types, visit_types,
visitor::Visit, visitor::Visit,
}; };
use rustc_hash::FxHashMap;
use smallvec::smallvec; use smallvec::smallvec;
use swc_core::{ use swc_core::{
base::sourcemap::SourceMapBuilder, base::sourcemap::SourceMapBuilder,
...@@ -148,7 +146,7 @@ pub enum CssWithPlaceholderResult { ...@@ -148,7 +146,7 @@ pub enum CssWithPlaceholderResult {
exports: Option<FxIndexMap<String, CssModuleExport>>, exports: Option<FxIndexMap<String, CssModuleExport>>,
#[turbo_tasks(trace_ignore)] #[turbo_tasks(trace_ignore)]
placeholders: HashMap<String, Url<'static>>, placeholders: FxHashMap<String, Url<'static>>,
}, },
Unparseable, Unparseable,
NotFound, NotFound,
...@@ -210,7 +208,7 @@ pub async fn process_css_with_placeholder( ...@@ -210,7 +208,7 @@ pub async fn process_css_with_placeholder(
exports, exports,
references: *references, references: *references,
url_references: *url_references, url_references: *url_references,
placeholders: HashMap::new(), placeholders: FxHashMap::default(),
} }
.cell()) .cell())
} }
...@@ -246,7 +244,7 @@ pub async fn finalize_css( ...@@ -246,7 +244,7 @@ pub async fn finalize_css(
let url_references = *url_references; let url_references = *url_references;
let mut url_map = HashMap::new(); let mut url_map = FxHashMap::default();
for (src, reference) in (*url_references.await?).iter() { for (src, reference) in (*url_references.await?).iter() {
let resolved = let resolved =
......
use std::{collections::HashMap, convert::Infallible}; use std::convert::Infallible;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use lightningcss::{ use lightningcss::{
...@@ -6,6 +6,7 @@ use lightningcss::{ ...@@ -6,6 +6,7 @@ use lightningcss::{
visit_types, visit_types,
visitor::{Visit, Visitor}, visitor::{Visit, Visitor},
}; };
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{debug::ValueDebug, ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks::{debug::ValueDebug, ResolvedVc, Value, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
...@@ -148,14 +149,14 @@ pub async fn resolve_url_reference( ...@@ -148,14 +149,14 @@ pub async fn resolve_url_reference(
pub fn replace_url_references( pub fn replace_url_references(
ss: &mut StyleSheetLike<'static, 'static>, ss: &mut StyleSheetLike<'static, 'static>,
urls: &HashMap<RcStr, RcStr>, urls: &FxHashMap<RcStr, RcStr>,
) { ) {
let mut replacer = AssetReferenceReplacer { urls }; let mut replacer = AssetReferenceReplacer { urls };
ss.0.visit(&mut replacer).unwrap(); ss.0.visit(&mut replacer).unwrap();
} }
struct AssetReferenceReplacer<'a> { struct AssetReferenceReplacer<'a> {
urls: &'a HashMap<RcStr, RcStr>, urls: &'a FxHashMap<RcStr, RcStr>,
} }
impl Visitor<'_> for AssetReferenceReplacer<'_> { impl Visitor<'_> for AssetReferenceReplacer<'_> {
......
...@@ -27,6 +27,7 @@ mime = { workspace = true } ...@@ -27,6 +27,7 @@ mime = { workspace = true }
mime_guess = "2.0.4" mime_guess = "2.0.4"
parking_lot = { workspace = true } parking_lot = { workspace = true }
pin-project-lite = { workspace = true } pin-project-lite = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
serde_qs = { workspace = true } serde_qs = { workspace = true }
...@@ -35,18 +36,17 @@ tokio = { workspace = true } ...@@ -35,18 +36,17 @@ tokio = { workspace = true }
tokio-stream = "0.1.9" tokio-stream = "0.1.9"
tokio-util = { workspace = true } tokio-util = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
urlencoding = "2.1.2"
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
turbo-tasks-bytes = { workspace = true } turbo-tasks-bytes = { workspace = true }
turbo-tasks-fs = { workspace = true } turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true } turbo-tasks-hash = { workspace = true }
# TODO remove this dependency
turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
turbopack-ecmascript = { workspace = true } turbopack-ecmascript = { workspace = true }
turbopack-ecmascript-hmr-protocol = { workspace = true } turbopack-ecmascript-hmr-protocol = { workspace = true }
# TODO remove this dependency urlencoding = "2.1.2"
turbopack-cli-utils = { workspace = true }
[build-dependencies] [build-dependencies]
turbo-tasks-build = { workspace = true } turbo-tasks-build = { workspace = true }
use std::{borrow::Cow, collections::HashSet, fmt::Display}; use std::{borrow::Cow, fmt::Display};
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashSet;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Vc}; use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_fs::{json::parse_json_with_source_context, File}; use turbo_tasks_fs::{json::parse_json_with_source_context, File};
...@@ -18,7 +19,7 @@ use crate::source::{ ...@@ -18,7 +19,7 @@ use crate::source::{
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct IntrospectionSource { pub struct IntrospectionSource {
pub roots: HashSet<ResolvedVc<Box<dyn Introspectable>>>, pub roots: FxHashSet<ResolvedVc<Box<dyn Introspectable>>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
use std::{ use std::{collections::VecDeque, iter::once};
collections::{HashSet, VecDeque},
iter::once,
};
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashSet;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
fxindexset, Completion, FxIndexMap, FxIndexSet, ResolvedVc, State, TryJoinIterExt, Value, fxindexset, Completion, FxIndexMap, FxIndexSet, ResolvedVc, State, TryJoinIterExt, Value,
...@@ -25,7 +23,7 @@ use super::{ ...@@ -25,7 +23,7 @@ use super::{
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
struct OutputAssetsMap(FxIndexMap<RcStr, ResolvedVc<Box<dyn OutputAsset>>>); struct OutputAssetsMap(FxIndexMap<RcStr, ResolvedVc<Box<dyn OutputAsset>>>);
type ExpandedState = State<HashSet<RcStr>>; type ExpandedState = State<FxHashSet<RcStr>>;
#[turbo_tasks::value(serialization = "none", eq = "manual", cell = "new")] #[turbo_tasks::value(serialization = "none", eq = "manual", cell = "new")]
pub struct AssetGraphContentSource { pub struct AssetGraphContentSource {
...@@ -59,7 +57,7 @@ impl AssetGraphContentSource { ...@@ -59,7 +57,7 @@ impl AssetGraphContentSource {
Self::cell(AssetGraphContentSource { Self::cell(AssetGraphContentSource {
root_path, root_path,
root_assets: ResolvedVc::cell(fxindexset! { root_asset }), root_assets: ResolvedVc::cell(fxindexset! { root_asset }),
expanded: Some(State::new(HashSet::new())), expanded: Some(State::new(FxHashSet::default())),
}) })
} }
...@@ -86,7 +84,7 @@ impl AssetGraphContentSource { ...@@ -86,7 +84,7 @@ impl AssetGraphContentSource {
Self::cell(AssetGraphContentSource { Self::cell(AssetGraphContentSource {
root_path, root_path,
root_assets, root_assets,
expanded: Some(State::new(HashSet::new())), expanded: Some(State::new(FxHashSet::default())),
}) })
} }
...@@ -111,7 +109,7 @@ async fn expand( ...@@ -111,7 +109,7 @@ async fn expand(
let mut map = FxIndexMap::default(); let mut map = FxIndexMap::default();
let mut assets = Vec::new(); let mut assets = Vec::new();
let mut queue = VecDeque::with_capacity(32); let mut queue = VecDeque::with_capacity(32);
let mut assets_set = HashSet::new(); let mut assets_set = FxHashSet::default();
let root_assets_with_path = root_assets let root_assets_with_path = root_assets
.iter() .iter()
.map(|&asset| async move { .map(|&asset| async move {
......
use std::{ use std::{collections::BTreeMap, fmt::Display};
collections::{BTreeMap, HashMap},
fmt::Display,
};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rustc_hash::FxHashSet; use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{ use swc_core::{
common::{comments::Comments, source_map::SmallPos, BytePos, Span, Spanned}, common::{comments::Comments, source_map::SmallPos, BytePos, Span, Spanned},
ecma::{ ecma::{
...@@ -176,7 +173,7 @@ pub(crate) struct ImportMap { ...@@ -176,7 +173,7 @@ pub(crate) struct ImportMap {
/// full details. /// full details.
/// ///
/// [magic]: https://webpack.js.org/api/module-methods/#magic-comments /// [magic]: https://webpack.js.org/api/module-methods/#magic-comments
attributes: HashMap<BytePos, ImportAttributes>, attributes: FxHashMap<BytePos, ImportAttributes>,
/// The module specifiers of star imports that are accessed dynamically and should be imported /// The module specifiers of star imports that are accessed dynamically and should be imported
/// as a whole. /// as a whole.
......
use std::{ use std::{collections::hash_map::Entry, future::Future, mem::take};
collections::{hash_map::Entry, HashSet},
future::Future,
mem::take,
};
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashMap; use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::ecma::ast::Id; use swc_core::ecma::ast::Id;
use super::{graph::VarGraph, JsValue}; use super::{graph::VarGraph, JsValue};
...@@ -60,7 +56,7 @@ where ...@@ -60,7 +56,7 @@ where
let mut done: Vec<JsValue> = Vec::new(); let mut done: Vec<JsValue> = Vec::new();
// Tracks the number of nodes in the queue and done combined // Tracks the number of nodes in the queue and done combined
let mut total_nodes = 0; let mut total_nodes = 0;
let mut cycle_stack: HashSet<Id> = HashSet::new(); let mut cycle_stack: FxHashSet<Id> = FxHashSet::default();
// Tracks the number linking steps so far // Tracks the number linking steps so far
let mut steps = 0; let mut steps = 0;
......
...@@ -17,12 +17,7 @@ pub mod unreachable; ...@@ -17,12 +17,7 @@ pub mod unreachable;
pub mod util; pub mod util;
pub mod worker; pub mod worker;
use std::{ use std::{borrow::Cow, collections::BTreeMap, mem::take, sync::Arc};
borrow::Cow,
collections::{BTreeMap, HashMap},
mem::take,
sync::Arc,
};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use constant_condition::{ConstantCondition, ConstantConditionValue}; use constant_condition::{ConstantCondition, ConstantConditionValue};
...@@ -2937,7 +2932,7 @@ enum StaticExpr { ...@@ -2937,7 +2932,7 @@ enum StaticExpr {
// TODO get rid of that // TODO get rid of that
#[derive(Default)] #[derive(Default)]
struct StaticAnalyser { struct StaticAnalyser {
imports: HashMap<String, (String, Vec<String>)>, imports: FxHashMap<String, (String, Vec<String>)>,
} }
impl StaticAnalyser { impl StaticAnalyser {
......
use std::{cell::RefCell, collections::HashMap, mem::take}; use std::{cell::RefCell, mem::take};
use rustc_hash::FxHashMap;
use swc_core::{ use swc_core::{
base::SwcComments, base::SwcComments,
common::{ common::{
...@@ -12,8 +13,8 @@ use swc_core::{ ...@@ -12,8 +13,8 @@ use swc_core::{
/// variants are still implemented, but do not mutate the content. They are used /// variants are still implemented, but do not mutate the content. They are used
/// by the SWC Emitter. /// by the SWC Emitter.
pub struct ImmutableComments { pub struct ImmutableComments {
pub leading: HashMap<BytePos, Vec<Comment>>, pub leading: FxHashMap<BytePos, Vec<Comment>>,
pub trailing: HashMap<BytePos, Vec<Comment>>, pub trailing: FxHashMap<BytePos, Vec<Comment>>,
} }
impl ImmutableComments { impl ImmutableComments {
...@@ -185,8 +186,8 @@ impl Comments for ImmutableComments { ...@@ -185,8 +186,8 @@ impl Comments for ImmutableComments {
} }
pub struct CowComments<'a> { pub struct CowComments<'a> {
leading: RefCell<HashMap<BytePos, &'a Vec<Comment>>>, leading: RefCell<FxHashMap<BytePos, &'a Vec<Comment>>>,
trailing: RefCell<HashMap<BytePos, &'a Vec<Comment>>>, trailing: RefCell<FxHashMap<BytePos, &'a Vec<Comment>>>,
} }
impl<'a> CowComments<'a> { impl<'a> CowComments<'a> {
......
...@@ -32,6 +32,7 @@ image = { workspace = true, default-features = false, features = [ ...@@ -32,6 +32,7 @@ image = { workspace = true, default-features = false, features = [
mime = { workspace = true } mime = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_with = { workspace = true } serde_with = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
......
// Ported from https://github.com/image-size/image-size/blob/94e9c1ee913b71222d7583dc904ac0116ae00834/lib/types/svg.ts // Ported from https://github.com/image-size/image-size/blob/94e9c1ee913b71222d7583dc904ac0116ae00834/lib/types/svg.ts
// see SVG_LICENSE for license info // see SVG_LICENSE for license info
use std::collections::HashMap;
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use rustc_hash::FxHashMap;
const INCH_CM: f64 = 2.54; const INCH_CM: f64 = 2.54;
static UNITS: Lazy<HashMap<&str, f64>> = Lazy::new(|| { static UNITS: Lazy<FxHashMap<&str, f64>> = Lazy::new(|| {
HashMap::from([ FxHashMap::from_iter([
("in", 96.0), ("in", 96.0),
("cm", 96.0 / INCH_CM), ("cm", 96.0 / INCH_CM),
("em", 16.0), ("em", 16.0),
......
...@@ -31,6 +31,7 @@ once_cell = { workspace = true } ...@@ -31,6 +31,7 @@ once_cell = { workspace = true }
owo-colors = { workspace = true } owo-colors = { workspace = true }
parking_lot = { workspace = true } parking_lot = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
serde_with = { workspace = true, features = ["base64"] } serde_with = { workspace = true, features = ["base64"] }
......
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
#![feature(arbitrary_self_types_pointers)] #![feature(arbitrary_self_types_pointers)]
#![feature(extract_if)] #![feature(extract_if)]
use std::{collections::HashMap, iter::once, thread::available_parallelism}; use std::{iter::once, thread::available_parallelism};
use anyhow::{bail, Result}; use anyhow::{bail, Result};
pub use node_entry::{NodeEntry, NodeRenderingEntries, NodeRenderingEntry}; pub use node_entry::{NodeEntry, NodeRenderingEntries, NodeRenderingEntry};
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
...@@ -80,7 +81,7 @@ async fn internal_assets( ...@@ -80,7 +81,7 @@ async fn internal_assets(
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct AssetsForSourceMapping(HashMap<String, ResolvedVc<Box<dyn GenerateSourceMap>>>); pub struct AssetsForSourceMapping(FxHashMap<String, ResolvedVc<Box<dyn GenerateSourceMap>>>);
/// Extracts a map of "internal" assets ([`internal_assets`]) which implement /// Extracts a map of "internal" assets ([`internal_assets`]) which implement
/// the [GenerateSourceMap] trait. /// the [GenerateSourceMap] trait.
...@@ -91,7 +92,7 @@ async fn internal_assets_for_source_mapping( ...@@ -91,7 +92,7 @@ async fn internal_assets_for_source_mapping(
) -> Result<Vc<AssetsForSourceMapping>> { ) -> Result<Vc<AssetsForSourceMapping>> {
let internal_assets = internal_assets(intermediate_asset, intermediate_output_path).await?; let internal_assets = internal_assets(intermediate_asset, intermediate_output_path).await?;
let intermediate_output_path = &*intermediate_output_path.await?; let intermediate_output_path = &*intermediate_output_path.await?;
let mut internal_assets_for_source_mapping = HashMap::new(); let mut internal_assets_for_source_mapping = FxHashMap::default();
for asset in internal_assets.iter() { for asset in internal_assets.iter() {
if let Some(generate_source_map) = if let Some(generate_source_map) =
ResolvedVc::try_sidecast::<Box<dyn GenerateSourceMap>>(*asset) ResolvedVc::try_sidecast::<Box<dyn GenerateSourceMap>>(*asset)
......
use std::{ use std::{
borrow::Cow, borrow::Cow,
cmp::max, cmp::max,
collections::HashMap,
fmt::{Debug, Display}, fmt::{Debug, Display},
future::Future, future::Future,
mem::take, mem::take,
...@@ -15,6 +14,7 @@ use anyhow::{bail, Context, Result}; ...@@ -15,6 +14,7 @@ use anyhow::{bail, Context, Result};
use futures::join; use futures::join;
use owo_colors::{OwoColorize, Style}; use owo_colors::{OwoColorize, Style};
use parking_lot::Mutex; use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use tokio::{ use tokio::{
io::{ io::{
...@@ -203,7 +203,7 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> { ...@@ -203,7 +203,7 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> {
} }
let mut buffer = Vec::new(); let mut buffer = Vec::new();
let mut own_output = HashMap::new(); let mut own_output = FxHashMap::default();
let mut nesting: u32 = 0; let mut nesting: u32 = 0;
let mut in_stack = None; let mut in_stack = None;
let mut stack_trace_buffer = Vec::new(); let mut stack_trace_buffer = Vec::new();
...@@ -309,7 +309,7 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> { ...@@ -309,7 +309,7 @@ impl<R: AsyncRead + Unpin, W: AsyncWrite + Unpin> OutputStreamHandler<R, W> {
impl NodeJsPoolProcess { impl NodeJsPoolProcess {
async fn new( async fn new(
cwd: &Path, cwd: &Path,
env: &HashMap<RcStr, RcStr>, env: &FxHashMap<RcStr, RcStr>,
entrypoint: &Path, entrypoint: &Path,
assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>, assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
assets_root: ResolvedVc<FileSystemPath>, assets_root: ResolvedVc<FileSystemPath>,
...@@ -688,7 +688,7 @@ enum AcquiredPermits { ...@@ -688,7 +688,7 @@ enum AcquiredPermits {
pub struct NodeJsPool { pub struct NodeJsPool {
cwd: PathBuf, cwd: PathBuf,
entrypoint: PathBuf, entrypoint: PathBuf,
env: HashMap<RcStr, RcStr>, env: FxHashMap<RcStr, RcStr>,
pub assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>, pub assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
pub assets_root: ResolvedVc<FileSystemPath>, pub assets_root: ResolvedVc<FileSystemPath>,
pub project_dir: ResolvedVc<FileSystemPath>, pub project_dir: ResolvedVc<FileSystemPath>,
...@@ -719,7 +719,7 @@ impl NodeJsPool { ...@@ -719,7 +719,7 @@ impl NodeJsPool {
pub(super) fn new( pub(super) fn new(
cwd: PathBuf, cwd: PathBuf,
entrypoint: PathBuf, entrypoint: PathBuf,
env: HashMap<RcStr, RcStr>, env: FxHashMap<RcStr, RcStr>,
assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>, assets_for_source_mapping: ResolvedVc<AssetsForSourceMapping>,
assets_root: ResolvedVc<FileSystemPath>, assets_root: ResolvedVc<FileSystemPath>,
project_dir: ResolvedVc<FileSystemPath>, project_dir: ResolvedVc<FileSystemPath>,
......
...@@ -24,6 +24,7 @@ turbo-tasks-fs = { workspace = true } ...@@ -24,6 +24,7 @@ turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true } turbo-tasks-hash = { workspace = true }
turbopack-cli-utils = { workspace = true } turbopack-cli-utils = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
rustc-hash = { workspace = true }
[build-dependencies] [build-dependencies]
turbo-tasks-build = { workspace = true } turbo-tasks-build = { workspace = true }
use std::{ use std::{env, fs, path::PathBuf};
collections::{HashMap, HashSet},
env, fs,
path::PathBuf,
};
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
use rustc_hash::{FxHashMap, FxHashSet};
use similar::TextDiff; use similar::TextDiff;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks::{ReadRef, TryJoinIterExt, ValueToString, Vc};
...@@ -33,7 +30,7 @@ pub async fn snapshot_issues<I: IntoIterator<Item = ReadRef<PlainIssue>>>( ...@@ -33,7 +30,7 @@ pub async fn snapshot_issues<I: IntoIterator<Item = ReadRef<PlainIssue>>>(
workspace_root: &str, workspace_root: &str,
) -> Result<()> { ) -> Result<()> {
let expected_issues = expected(issues_path).await?; let expected_issues = expected(issues_path).await?;
let mut seen = HashSet::new(); let mut seen = FxHashSet::default();
for plain_issue in captured_issues.into_iter() { for plain_issue in captured_issues.into_iter() {
let title = styled_string_to_file_safe_string(&plain_issue.title) let title = styled_string_to_file_safe_string(&plain_issue.title)
.replace('/', "__") .replace('/', "__")
...@@ -85,8 +82,8 @@ pub async fn snapshot_issues<I: IntoIterator<Item = ReadRef<PlainIssue>>>( ...@@ -85,8 +82,8 @@ pub async fn snapshot_issues<I: IntoIterator<Item = ReadRef<PlainIssue>>>(
matches_expected(expected_issues, seen).await matches_expected(expected_issues, seen).await
} }
pub async fn expected(dir: Vc<FileSystemPath>) -> Result<HashSet<Vc<FileSystemPath>>> { pub async fn expected(dir: Vc<FileSystemPath>) -> Result<FxHashSet<Vc<FileSystemPath>>> {
let mut expected = HashSet::new(); let mut expected = FxHashSet::default();
let entries = dir.read_dir().await?; let entries = dir.read_dir().await?;
if let DirectoryContent::Entries(entries) = &*entries { if let DirectoryContent::Entries(entries) = &*entries {
for (file, entry) in entries { for (file, entry) in entries {
...@@ -106,8 +103,8 @@ pub async fn expected(dir: Vc<FileSystemPath>) -> Result<HashSet<Vc<FileSystemPa ...@@ -106,8 +103,8 @@ pub async fn expected(dir: Vc<FileSystemPath>) -> Result<HashSet<Vc<FileSystemPa
} }
pub async fn matches_expected( pub async fn matches_expected(
expected: HashSet<Vc<FileSystemPath>>, expected: FxHashSet<Vc<FileSystemPath>>,
seen: HashSet<Vc<FileSystemPath>>, seen: FxHashSet<Vc<FileSystemPath>>,
) -> Result<()> { ) -> Result<()> {
for path in diff_paths(&expected, &seen).await? { for path in diff_paths(&expected, &seen).await? {
let p = &path.await?.path; let p = &path.await?.path;
...@@ -195,9 +192,9 @@ async fn remove_file(path: Vc<FileSystemPath>) -> Result<()> { ...@@ -195,9 +192,9 @@ async fn remove_file(path: Vc<FileSystemPath>) -> Result<()> {
/// Vc<FileSystemPath> hashes as a Vc, not as the file path, so we need to get /// Vc<FileSystemPath> hashes as a Vc, not as the file path, so we need to get
/// the path to properly diff. /// the path to properly diff.
async fn diff_paths( async fn diff_paths(
left: &HashSet<Vc<FileSystemPath>>, left: &FxHashSet<Vc<FileSystemPath>>,
right: &HashSet<Vc<FileSystemPath>>, right: &FxHashSet<Vc<FileSystemPath>>,
) -> Result<HashSet<Vc<FileSystemPath>>> { ) -> Result<FxHashSet<Vc<FileSystemPath>>> {
let mut map = left let mut map = left
.iter() .iter()
.map(|p| async move { Ok((p.await?.path.clone(), *p)) }) .map(|p| async move { Ok((p.await?.path.clone(), *p)) })
...@@ -205,7 +202,7 @@ async fn diff_paths( ...@@ -205,7 +202,7 @@ async fn diff_paths(
.await? .await?
.iter() .iter()
.cloned() .cloned()
.collect::<HashMap<_, _>>(); .collect::<FxHashMap<_, _>>();
for p in right { for p in right {
map.remove(&p.await?.path); map.remove(&p.await?.path);
} }
......
...@@ -21,6 +21,7 @@ dunce = { workspace = true } ...@@ -21,6 +21,7 @@ dunce = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
indexmap = { workspace = true } indexmap = { workspace = true }
once_cell = { workspace = true } once_cell = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
testing = { workspace = true } testing = { workspace = true }
......
...@@ -3,14 +3,11 @@ ...@@ -3,14 +3,11 @@
mod util; mod util;
use std::{ use std::{collections::VecDeque, fs, path::PathBuf};
collections::{HashSet, VecDeque},
fs,
path::PathBuf,
};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use dunce::canonicalize; use dunce::canonicalize;
use rustc_hash::FxHashSet;
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
...@@ -451,7 +448,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -451,7 +448,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
bail!("Entry module is not chunkable, so it can't be used to bootstrap the application") bail!("Entry module is not chunkable, so it can't be used to bootstrap the application")
}; };
let mut seen = HashSet::new(); let mut seen = FxHashSet::default();
let mut queue: VecDeque<_> = chunks.await?.iter().copied().collect(); let mut queue: VecDeque<_> = chunks.await?.iter().copied().collect();
let output_path = project_path.await?; let output_path = project_path.await?;
...@@ -478,7 +475,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -478,7 +475,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
async fn walk_asset( async fn walk_asset(
asset: ResolvedVc<Box<dyn OutputAsset>>, asset: ResolvedVc<Box<dyn OutputAsset>>,
output_path: &ReadRef<FileSystemPath>, output_path: &ReadRef<FileSystemPath>,
seen: &mut HashSet<Vc<FileSystemPath>>, seen: &mut FxHashSet<Vc<FileSystemPath>>,
queue: &mut VecDeque<ResolvedVc<Box<dyn OutputAsset>>>, queue: &mut VecDeque<ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result<()> { ) -> Result<()> {
let path = asset.ident().path().resolve().await?; let path = asset.ident().path().resolve().await?;
......
use std::{collections::HashMap, env, sync::Arc}; use std::{env, sync::Arc};
use rustc_hash::FxHashMap;
use crate::{ use crate::{
span::{SpanBottomUp, SpanIndex}, span::{SpanBottomUp, SpanIndex},
...@@ -8,7 +10,7 @@ use crate::{ ...@@ -8,7 +10,7 @@ use crate::{
pub struct SpanBottomUpBuilder { pub struct SpanBottomUpBuilder {
// These values won't change after creation: // These values won't change after creation:
pub self_spans: Vec<SpanIndex>, pub self_spans: Vec<SpanIndex>,
pub children: HashMap<String, SpanBottomUpBuilder>, pub children: FxHashMap<String, SpanBottomUpBuilder>,
pub example_span: SpanIndex, pub example_span: SpanIndex,
} }
...@@ -16,7 +18,7 @@ impl SpanBottomUpBuilder { ...@@ -16,7 +18,7 @@ impl SpanBottomUpBuilder {
pub fn new(example_span: SpanIndex) -> Self { pub fn new(example_span: SpanIndex) -> Self {
Self { Self {
self_spans: vec![], self_spans: vec![],
children: HashMap::new(), children: FxHashMap::default(),
example_span, example_span,
} }
} }
...@@ -40,7 +42,7 @@ pub fn build_bottom_up_graph<'a>( ...@@ -40,7 +42,7 @@ pub fn build_bottom_up_graph<'a>(
.ok() .ok()
.and_then(|s| s.parse().ok()) .and_then(|s| s.parse().ok())
.unwrap_or(usize::MAX); .unwrap_or(usize::MAX);
let mut roots = HashMap::new(); let mut roots = FxHashMap::default();
// unfortunately there is a rustc bug that fails the typechecking here // unfortunately there is a rustc bug that fails the typechecking here
// when using Either<impl Iterator, impl Iterator>. This error appears // when using Either<impl Iterator, impl Iterator>. This error appears
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
use std::{hash::BuildHasherDefault, sync::Arc}; use std::{hash::BuildHasherDefault, sync::Arc};
use indexmap::IndexSet; use indexmap::{IndexMap, IndexSet};
use rustc_hash::FxHasher; use rustc_hash::FxHasher;
use self::{reader::TraceReader, server::serve, store_container::StoreContainer}; use self::{reader::TraceReader, server::serve, store_container::StoreContainer};
...@@ -23,10 +23,11 @@ mod u64_empty_string; ...@@ -23,10 +23,11 @@ mod u64_empty_string;
mod u64_string; mod u64_string;
mod viewer; mod viewer;
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>; type FxIndexSet<T> = IndexSet<T, BuildHasherDefault<FxHasher>>;
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
fn main() { fn main() {
let args: IndexSet<String> = std::env::args().skip(1).collect(); let args: FxIndexSet<String> = std::env::args().skip(1).collect();
let mut iter = args.iter(); let mut iter = args.iter();
let arg = iter.next().expect("missing argument: trace file path"); let arg = iter.next().expect("missing argument: trace file path");
......
use std::{ use std::{env, str::from_utf8, sync::Arc};
collections::{HashMap, HashSet},
env,
str::from_utf8,
sync::Arc,
};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use indexmap::map::Entry; use indexmap::map::Entry;
use rustc_demangle::demangle; use rustc_demangle::demangle;
use rustc_hash::{FxHashMap, FxHashSet};
use super::TraceFormat; use super::TraceFormat;
use crate::{span::SpanIndex, store_container::StoreContainer, FxIndexMap}; use crate::{span::SpanIndex, store_container::StoreContainer, FxIndexMap};
...@@ -94,13 +90,13 @@ pub struct HeaptrackFormat { ...@@ -94,13 +90,13 @@ pub struct HeaptrackFormat {
last_timestamp: u64, last_timestamp: u64,
strings: Vec<String>, strings: Vec<String>,
traces: Vec<TraceData>, traces: Vec<TraceData>,
ip_parent_map: HashMap<(usize, SpanIndex), usize>, ip_parent_map: FxHashMap<(usize, SpanIndex), usize>,
trace_instruction_pointers: Vec<usize>, trace_instruction_pointers: Vec<usize>,
instruction_pointers: FxIndexMap<InstructionPointer, InstructionPointerExtraInfo>, instruction_pointers: FxIndexMap<InstructionPointer, InstructionPointerExtraInfo>,
allocations: Vec<AllocationInfo>, allocations: Vec<AllocationInfo>,
spans: usize, spans: usize,
collapse_crates: HashSet<String>, collapse_crates: FxHashSet<String>,
expand_crates: HashSet<String>, expand_crates: FxHashSet<String>,
expand_recursion: bool, expand_recursion: bool,
allocated_memory: u64, allocated_memory: u64,
temp_allocated_memory: u64, temp_allocated_memory: u64,
...@@ -120,7 +116,7 @@ impl HeaptrackFormat { ...@@ -120,7 +116,7 @@ impl HeaptrackFormat {
ip_index: 0, ip_index: 0,
parent_trace_index: 0, parent_trace_index: 0,
}], }],
ip_parent_map: HashMap::new(), ip_parent_map: FxHashMap::default(),
instruction_pointers: { instruction_pointers: {
let mut map = FxIndexMap::with_capacity_and_hasher(2, Default::default()); let mut map = FxIndexMap::with_capacity_and_hasher(2, Default::default());
map.insert( map.insert(
...@@ -185,7 +181,7 @@ impl TraceFormat for HeaptrackFormat { ...@@ -185,7 +181,7 @@ impl TraceFormat for HeaptrackFormat {
fn read(&mut self, mut buffer: &[u8], _reuse: &mut Self::Reused) -> anyhow::Result<usize> { fn read(&mut self, mut buffer: &[u8], _reuse: &mut Self::Reused) -> anyhow::Result<usize> {
let mut bytes_read = 0; let mut bytes_read = 0;
let mut outdated_spans = HashSet::new(); let mut outdated_spans = FxHashSet::default();
let mut store = self.store.write(); let mut store = self.store.write();
'outer: loop { 'outer: loop {
let Some(line_end) = buffer.iter().position(|b| *b == b'\n') else { let Some(line_end) = buffer.iter().position(|b| *b == b'\n') else {
......
use std::{ use std::{borrow::Cow, fmt::Display, sync::Arc};
borrow::Cow,
collections::{HashMap, HashSet},
fmt::Display,
sync::Arc,
};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::Deserialize; use serde::Deserialize;
use super::TraceFormat; use super::TraceFormat;
...@@ -12,16 +8,16 @@ use crate::{span::SpanIndex, store_container::StoreContainer, FxIndexMap}; ...@@ -12,16 +8,16 @@ use crate::{span::SpanIndex, store_container::StoreContainer, FxIndexMap};
pub struct NextJsFormat { pub struct NextJsFormat {
store: Arc<StoreContainer>, store: Arc<StoreContainer>,
id_mapping: HashMap<u64, SpanIndex>, id_mapping: FxHashMap<u64, SpanIndex>,
queued_children: HashMap<u64, Vec<SpanIndex>>, queued_children: FxHashMap<u64, Vec<SpanIndex>>,
} }
impl NextJsFormat { impl NextJsFormat {
pub fn new(store: Arc<StoreContainer>) -> Self { pub fn new(store: Arc<StoreContainer>) -> Self {
Self { Self {
store, store,
id_mapping: HashMap::new(), id_mapping: FxHashMap::default(),
queued_children: HashMap::new(), queued_children: FxHashMap::default(),
} }
} }
} }
...@@ -31,7 +27,7 @@ impl TraceFormat for NextJsFormat { ...@@ -31,7 +27,7 @@ impl TraceFormat for NextJsFormat {
fn read(&mut self, mut buffer: &[u8], _reuse: &mut Self::Reused) -> anyhow::Result<usize> { fn read(&mut self, mut buffer: &[u8], _reuse: &mut Self::Reused) -> anyhow::Result<usize> {
let mut bytes_read = 0; let mut bytes_read = 0;
let mut outdated_spans = HashSet::new(); let mut outdated_spans = FxHashSet::default();
loop { loop {
let Some(line_end) = buffer.iter().position(|b| *b == b'\n') else { let Some(line_end) = buffer.iter().position(|b| *b == b'\n') else {
break; break;
......
use std::{ use std::{
borrow::Cow, borrow::Cow,
collections::{hash_map::Entry, HashMap, HashSet}, collections::hash_map::Entry,
mem::transmute, mem::transmute,
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
sync::Arc, sync::Arc,
}; };
use anyhow::Result; use anyhow::Result;
use rustc_hash::{FxHashMap, FxHashSet};
use turbopack_trace_utils::tracing::{TraceRow, TraceValue}; use turbopack_trace_utils::tracing::{TraceRow, TraceValue};
use super::TraceFormat; use super::TraceFormat;
...@@ -129,24 +130,24 @@ struct QueuedRows { ...@@ -129,24 +130,24 @@ struct QueuedRows {
pub struct TurbopackFormat { pub struct TurbopackFormat {
store: Arc<StoreContainer>, store: Arc<StoreContainer>,
id_mapping: HashMap<u64, SpanIndex>, id_mapping: FxHashMap<u64, SpanIndex>,
queued_rows: HashMap<u64, QueuedRows>, queued_rows: FxHashMap<u64, QueuedRows>,
outdated_spans: HashSet<SpanIndex>, outdated_spans: FxHashSet<SpanIndex>,
thread_stacks: HashMap<u64, Vec<u64>>, thread_stacks: FxHashMap<u64, Vec<u64>>,
thread_allocation_counters: HashMap<u64, AllocationInfo>, thread_allocation_counters: FxHashMap<u64, AllocationInfo>,
self_time_started: HashMap<(u64, u64), u64>, self_time_started: FxHashMap<(u64, u64), u64>,
} }
impl TurbopackFormat { impl TurbopackFormat {
pub fn new(store: Arc<StoreContainer>) -> Self { pub fn new(store: Arc<StoreContainer>) -> Self {
Self { Self {
store, store,
id_mapping: HashMap::new(), id_mapping: FxHashMap::default(),
queued_rows: HashMap::new(), queued_rows: FxHashMap::default(),
outdated_spans: HashSet::new(), outdated_spans: FxHashSet::default(),
thread_stacks: HashMap::new(), thread_stacks: FxHashMap::default(),
thread_allocation_counters: HashMap::new(), thread_allocation_counters: FxHashMap::default(),
self_time_started: HashMap::new(), self_time_started: FxHashMap::default(),
} }
} }
......
use std::{ use std::{
collections::HashMap,
num::NonZeroUsize, num::NonZeroUsize,
sync::{Arc, OnceLock}, sync::{Arc, OnceLock},
}; };
use rustc_hash::FxHashMap;
pub type SpanIndex = NonZeroUsize; pub type SpanIndex = NonZeroUsize;
pub struct Span { pub struct Span {
...@@ -61,7 +62,7 @@ pub struct SpanTimeData { ...@@ -61,7 +62,7 @@ pub struct SpanTimeData {
pub struct SpanExtra { pub struct SpanExtra {
pub graph: OnceLock<Vec<SpanGraphEvent>>, pub graph: OnceLock<Vec<SpanGraphEvent>>,
pub bottom_up: OnceLock<Vec<Arc<SpanBottomUp>>>, pub bottom_up: OnceLock<Vec<Arc<SpanBottomUp>>>,
pub search_index: OnceLock<HashMap<String, Vec<SpanIndex>>>, pub search_index: OnceLock<FxHashMap<String, Vec<SpanIndex>>>,
} }
#[derive(Default)] #[derive(Default)]
......
use std::{ use std::{
cmp::max, cmp::max,
collections::{HashMap, HashSet, VecDeque}, collections::VecDeque,
fmt::{Debug, Formatter}, fmt::{Debug, Formatter},
vec, vec,
}; };
use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use rustc_hash::{FxHashMap, FxHashSet};
use crate::{ use crate::{
bottom_up::build_bottom_up_graph, bottom_up::build_bottom_up_graph,
...@@ -388,7 +389,7 @@ impl<'a> SpanRef<'a> { ...@@ -388,7 +389,7 @@ impl<'a> SpanRef<'a> {
pub fn search(&self, query: &str) -> impl Iterator<Item = SpanRef<'a>> { pub fn search(&self, query: &str) -> impl Iterator<Item = SpanRef<'a>> {
let mut query_items = query.split(",").map(str::trim); let mut query_items = query.split(",").map(str::trim);
let index = self.search_index(); let index = self.search_index();
let mut result = HashSet::new(); let mut result = FxHashSet::default();
let query = query_items.next().unwrap(); let query = query_items.next().unwrap();
for (key, spans) in index { for (key, spans) in index {
if key.contains(query) { if key.contains(query) {
...@@ -396,7 +397,7 @@ impl<'a> SpanRef<'a> { ...@@ -396,7 +397,7 @@ impl<'a> SpanRef<'a> {
} }
} }
for query in query_items { for query in query_items {
let mut and_result = HashSet::new(); let mut and_result = FxHashSet::default();
for (key, spans) in index { for (key, spans) in index {
if key.contains(query) { if key.contains(query) {
and_result.extend(spans.iter().copied()); and_result.extend(spans.iter().copied());
...@@ -412,9 +413,9 @@ impl<'a> SpanRef<'a> { ...@@ -412,9 +413,9 @@ impl<'a> SpanRef<'a> {
}) })
} }
fn search_index(&self) -> &HashMap<String, Vec<SpanIndex>> { fn search_index(&self) -> &FxHashMap<String, Vec<SpanIndex>> {
self.extra().search_index.get_or_init(|| { self.extra().search_index.get_or_init(|| {
let mut index: HashMap<String, Vec<SpanIndex>> = HashMap::new(); let mut index: FxHashMap<String, Vec<SpanIndex>> = FxHashMap::default();
let mut queue = VecDeque::with_capacity(8); let mut queue = VecDeque::with_capacity(8);
queue.push_back(*self); queue.push_back(*self);
while let Some(span) = queue.pop_front() { while let Some(span) = queue.pop_front() {
......
use std::{ use std::{
cmp::{max, min}, cmp::{max, min},
collections::HashSet,
env, env,
mem::replace, mem::replace,
num::NonZeroUsize, num::NonZeroUsize,
sync::{atomic::AtomicU64, OnceLock}, sync::{atomic::AtomicU64, OnceLock},
}; };
use rustc_hash::FxHashSet;
use crate::{ use crate::{
self_time_tree::SelfTimeTree, self_time_tree::SelfTimeTree,
span::{Span, SpanEvent, SpanIndex}, span::{Span, SpanEvent, SpanIndex},
...@@ -83,7 +84,7 @@ impl Store { ...@@ -83,7 +84,7 @@ impl Store {
category: String, category: String,
name: String, name: String,
args: Vec<(String, String)>, args: Vec<(String, String)>,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) -> SpanIndex { ) -> SpanIndex {
let id = SpanIndex::new(self.spans.len()).unwrap(); let id = SpanIndex::new(self.spans.len()).unwrap();
self.spans.push(Span { self.spans.push(Span {
...@@ -129,7 +130,7 @@ impl Store { ...@@ -129,7 +130,7 @@ impl Store {
&mut self, &mut self,
span_index: SpanIndex, span_index: SpanIndex,
args: Vec<(String, String)>, args: Vec<(String, String)>,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
let span = &mut self.spans[span_index.get()]; let span = &mut self.spans[span_index.get()];
span.args.extend(args); span.args.extend(args);
...@@ -158,7 +159,7 @@ impl Store { ...@@ -158,7 +159,7 @@ impl Store {
start: u64, start: u64,
end: u64, end: u64,
span_index: SpanIndex, span_index: SpanIndex,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
if let Some(tree) = self.self_time_tree.as_mut() { if let Some(tree) = self.self_time_tree.as_mut() {
if *self.max_self_time_lookup_time.get_mut() >= start { if *self.max_self_time_lookup_time.get_mut() >= start {
...@@ -175,7 +176,7 @@ impl Store { ...@@ -175,7 +176,7 @@ impl Store {
span_index: SpanIndex, span_index: SpanIndex,
start: u64, start: u64,
end: u64, end: u64,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
let span = &mut self.spans[span_index.get()]; let span = &mut self.spans[span_index.get()];
let time_data = span.time_data_mut(); let time_data = span.time_data_mut();
...@@ -194,7 +195,7 @@ impl Store { ...@@ -194,7 +195,7 @@ impl Store {
span_index: SpanIndex, span_index: SpanIndex,
start_time: u64, start_time: u64,
total_time: u64, total_time: u64,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
let span = SpanRef { let span = SpanRef {
span: &self.spans[span_index.get()], span: &self.spans[span_index.get()],
...@@ -258,7 +259,7 @@ impl Store { ...@@ -258,7 +259,7 @@ impl Store {
&mut self, &mut self,
span_index: SpanIndex, span_index: SpanIndex,
parent: SpanIndex, parent: SpanIndex,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
outdated_spans.insert(span_index); outdated_spans.insert(span_index);
let span = &mut self.spans[span_index.get()]; let span = &mut self.spans[span_index.get()];
...@@ -288,7 +289,7 @@ impl Store { ...@@ -288,7 +289,7 @@ impl Store {
span_index: SpanIndex, span_index: SpanIndex,
allocation: u64, allocation: u64,
count: u64, count: u64,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
let span = &mut self.spans[span_index.get()]; let span = &mut self.spans[span_index.get()];
outdated_spans.insert(span_index); outdated_spans.insert(span_index);
...@@ -301,7 +302,7 @@ impl Store { ...@@ -301,7 +302,7 @@ impl Store {
span_index: SpanIndex, span_index: SpanIndex,
deallocation: u64, deallocation: u64,
count: u64, count: u64,
outdated_spans: &mut HashSet<SpanIndex>, outdated_spans: &mut FxHashSet<SpanIndex>,
) { ) {
let span = &mut self.spans[span_index.get()]; let span = &mut self.spans[span_index.get()];
outdated_spans.insert(span_index); outdated_spans.insert(span_index);
...@@ -314,7 +315,7 @@ impl Store { ...@@ -314,7 +315,7 @@ impl Store {
span.is_complete = true; span.is_complete = true;
} }
pub fn invalidate_outdated_spans(&mut self, outdated_spans: &HashSet<SpanId>) { pub fn invalidate_outdated_spans(&mut self, outdated_spans: &FxHashSet<SpanId>) {
fn invalidate_span(span: &mut Span) { fn invalidate_span(span: &mut Span) {
if let Some(time_data) = span.time_data.get_mut() { if let Some(time_data) = span.time_data.get_mut() {
time_data.end.take(); time_data.end.take();
......
use std::{ use std::cmp::{max, Reverse};
cmp::{max, Reverse},
collections::{HashMap, HashSet},
};
use either::Either; use either::Either;
use itertools::Itertools; use itertools::Itertools;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use rustc_hash::{FxHashMap, FxHashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
...@@ -22,7 +20,7 @@ const EXTRA_HEIGHT: u64 = 5; ...@@ -22,7 +20,7 @@ const EXTRA_HEIGHT: u64 = 5;
#[derive(Default)] #[derive(Default)]
pub struct Viewer { pub struct Viewer {
span_options: HashMap<SpanId, SpanOptions>, span_options: FxHashMap<SpanId, SpanOptions>,
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
...@@ -341,8 +339,8 @@ impl Viewer { ...@@ -341,8 +339,8 @@ impl Viewer {
} }
pub fn compute_update(&mut self, store: &Store, view_rect: &ViewRect) -> Update { pub fn compute_update(&mut self, store: &Store, view_rect: &ViewRect) -> Update {
let mut highlighted_spans: HashSet<SpanId> = HashSet::new(); let mut highlighted_spans: FxHashSet<SpanId> = FxHashSet::default();
let mut highlighted_span_parents: HashSet<SpanId> = HashSet::new(); let mut highlighted_span_parents: FxHashSet<SpanId> = FxHashSet::default();
let search_mode = !view_rect.query.is_empty(); let search_mode = !view_rect.query.is_empty();
let (query, focus_mode) = if let Some(query) = view_rect.query.strip_suffix('!') { let (query, focus_mode) = if let Some(query) = view_rect.query.strip_suffix('!') {
(query, true) (query, true)
......
use std::{collections::HashMap, hash::BuildHasherDefault, str::FromStr}; use std::str::FromStr;
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHasher; use rustc_hash::FxHashMap;
use tracing::{level_filters::LevelFilter, Subscriber}; use tracing::{level_filters::LevelFilter, Subscriber};
use tracing_subscriber::Layer; use tracing_subscriber::Layer;
pub struct FilterLayer { pub struct FilterLayer {
config: HashMap<String, LevelFilter, BuildHasherDefault<FxHasher>>, config: FxHashMap<String, LevelFilter>,
global_level: LevelFilter, global_level: LevelFilter,
} }
impl FilterLayer { impl FilterLayer {
pub fn try_new(input: &str) -> Result<Self> { pub fn try_new(input: &str) -> Result<Self> {
let mut config = HashMap::default(); let mut config = FxHashMap::default();
let mut global_level = LevelFilter::OFF; let mut global_level = LevelFilter::OFF;
for entry in input.split(',') { for entry in input.split(',') {
if entry.is_empty() { if entry.is_empty() {
......
use std::collections::HashSet;
use anyhow::Result; use anyhow::Result;
use rustc_hash::FxHashSet;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::output::OutputAsset; use turbopack_core::output::OutputAsset;
...@@ -9,8 +8,8 @@ pub enum AggregatedGraph { ...@@ -9,8 +8,8 @@ pub enum AggregatedGraph {
Leaf(ResolvedVc<Box<dyn OutputAsset>>), Leaf(ResolvedVc<Box<dyn OutputAsset>>),
Node { Node {
depth: usize, depth: usize,
content: HashSet<ResolvedVc<AggregatedGraph>>, content: FxHashSet<ResolvedVc<AggregatedGraph>>,
references: HashSet<ResolvedVc<AggregatedGraph>>, references: FxHashSet<ResolvedVc<AggregatedGraph>>,
}, },
} }
...@@ -47,7 +46,7 @@ impl AggregatedGraph { ...@@ -47,7 +46,7 @@ impl AggregatedGraph {
async fn references(self: Vc<Self>) -> Result<Vc<AggregatedGraphsSet>> { async fn references(self: Vc<Self>) -> Result<Vc<AggregatedGraphsSet>> {
Ok(match &*self.await? { Ok(match &*self.await? {
AggregatedGraph::Leaf(asset) => { AggregatedGraph::Leaf(asset) => {
let mut refs = HashSet::new(); let mut refs = FxHashSet::default();
for reference in asset.references().await? { for reference in asset.references().await? {
if asset != reference { if asset != reference {
refs.insert(AggregatedGraph::leaf(**reference).to_resolved().await?); refs.insert(AggregatedGraph::leaf(**reference).to_resolved().await?);
...@@ -56,7 +55,7 @@ impl AggregatedGraph { ...@@ -56,7 +55,7 @@ impl AggregatedGraph {
AggregatedGraphsSet { set: refs }.into() AggregatedGraphsSet { set: refs }.into()
} }
AggregatedGraph::Node { references, .. } => { AggregatedGraph::Node { references, .. } => {
let mut set = HashSet::new(); let mut set = FxHashSet::default();
for item in references for item in references
.iter() .iter()
.map(|&reference| aggregate_more(*reference)) .map(|&reference| aggregate_more(*reference))
...@@ -83,9 +82,9 @@ impl AggregatedGraph { ...@@ -83,9 +82,9 @@ impl AggregatedGraph {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn valued_references(self: Vc<Self>) -> Result<Vc<AggregatedGraphsValuedReferences>> { async fn valued_references(self: Vc<Self>) -> Result<Vc<AggregatedGraphsValuedReferences>> {
let self_cost = self.cost().await?.0; let self_cost = self.cost().await?.0;
let mut inner = HashSet::new(); let mut inner = FxHashSet::default();
let mut outer = HashSet::new(); let mut outer = FxHashSet::default();
let mut references = HashSet::new(); let mut references = FxHashSet::default();
for (reference, cost) in self for (reference, cost) in self
.references() .references()
.await? .await?
...@@ -131,9 +130,9 @@ struct AggregationCost(usize); ...@@ -131,9 +130,9 @@ struct AggregationCost(usize);
async fn aggregate_more(node: ResolvedVc<AggregatedGraph>) -> Result<Vc<AggregatedGraph>> { async fn aggregate_more(node: ResolvedVc<AggregatedGraph>) -> Result<Vc<AggregatedGraph>> {
let node_data = node.await?; let node_data = node.await?;
let depth = node_data.depth(); let depth = node_data.depth();
let mut in_progress = HashSet::new(); let mut in_progress = FxHashSet::default();
let mut content = HashSet::new(); let mut content = FxHashSet::default();
let mut references = HashSet::new(); let mut references = FxHashSet::default();
in_progress.insert(node); in_progress.insert(node);
// only one kind of aggregation can't eliminate cycles with that // only one kind of aggregation can't eliminate cycles with that
...@@ -181,18 +180,18 @@ async fn aggregate_more(node: ResolvedVc<AggregatedGraph>) -> Result<Vc<Aggregat ...@@ -181,18 +180,18 @@ async fn aggregate_more(node: ResolvedVc<AggregatedGraph>) -> Result<Vc<Aggregat
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
struct AggregatedGraphsSet { struct AggregatedGraphsSet {
pub set: HashSet<ResolvedVc<AggregatedGraph>>, pub set: FxHashSet<ResolvedVc<AggregatedGraph>>,
} }
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub enum AggregatedGraphNodeContent { pub enum AggregatedGraphNodeContent {
Asset(ResolvedVc<Box<dyn OutputAsset>>), Asset(ResolvedVc<Box<dyn OutputAsset>>),
Children(HashSet<ResolvedVc<AggregatedGraph>>), Children(FxHashSet<ResolvedVc<AggregatedGraph>>),
} }
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
struct AggregatedGraphsValuedReferences { struct AggregatedGraphsValuedReferences {
pub inner: HashSet<ResolvedVc<AggregatedGraph>>, pub inner: FxHashSet<ResolvedVc<AggregatedGraph>>,
pub outer: HashSet<ResolvedVc<AggregatedGraph>>, pub outer: FxHashSet<ResolvedVc<AggregatedGraph>>,
pub references: HashSet<ResolvedVc<AggregatedGraph>>, pub references: FxHashSet<ResolvedVc<AggregatedGraph>>,
} }
pub(crate) mod context_transition; pub(crate) mod context_transition;
pub(crate) mod full_context_transition; pub(crate) mod full_context_transition;
use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
pub use context_transition::ContextTransition; pub use context_transition::ContextTransition;
pub use full_context_transition::FullContextTransition; pub use full_context_transition::FullContextTransition;
use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, ValueDefault, Vc}; use turbo_tasks::{ResolvedVc, Value, ValueDefault, Vc};
use turbopack_core::{ use turbopack_core::{
...@@ -121,7 +120,7 @@ pub trait Transition { ...@@ -121,7 +120,7 @@ pub trait Transition {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Default)] #[derive(Default)]
pub struct TransitionOptions { pub struct TransitionOptions {
pub named_transitions: HashMap<RcStr, ResolvedVc<Box<dyn Transition>>>, pub named_transitions: FxHashMap<RcStr, ResolvedVc<Box<dyn Transition>>>,
pub transition_rules: Vec<TransitionRule>, pub transition_rules: Vec<TransitionRule>,
pub placeholder_for_future_extensions: (), pub placeholder_for_future_extensions: (),
} }
......
...@@ -25,6 +25,7 @@ indexmap = { workspace = true } ...@@ -25,6 +25,7 @@ indexmap = { workspace = true }
inquire = { version = "0.5.1" } inquire = { version = "0.5.1" }
num-format = "0.4.4" num-format = "0.4.4"
owo-colors = { workspace = true } owo-colors = { workspace = true }
rustc-hash = { workspace = true }
semver = { workspace = true } semver = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true, features = ["preserve_order"] } serde_json = { workspace = true, features = ["preserve_order"] }
......
use std::{ use std::{
collections::{HashMap, HashSet},
env::{current_dir, var_os}, env::{current_dir, var_os},
path::PathBuf, path::PathBuf,
process, process,
...@@ -18,6 +17,7 @@ mod visualize_bundler_bench; ...@@ -18,6 +17,7 @@ mod visualize_bundler_bench;
use nft_bench::show_result; use nft_bench::show_result;
use patch_package_json::PatchPackageJsonArgs; use patch_package_json::PatchPackageJsonArgs;
use publish::{publish_workspace, run_bump, run_publish}; use publish::{publish_workspace, run_bump, run_publish};
use rustc_hash::{FxHashMap, FxHashSet};
fn cli() -> Command { fn cli() -> Command {
Command::new("xtask") Command::new("xtask")
...@@ -94,7 +94,7 @@ fn main() -> Result<()> { ...@@ -94,7 +94,7 @@ fn main() -> Result<()> {
if is_bump { if is_bump {
let names = sub_matches let names = sub_matches
.get_many::<String>("NAME") .get_many::<String>("NAME")
.map(|names| names.cloned().collect::<HashSet<_>>()) .map(|names| names.cloned().collect::<FxHashSet<_>>())
.unwrap_or_default(); .unwrap_or_default();
run_bump(names, dry_run); run_bump(names, dry_run);
} }
...@@ -125,14 +125,14 @@ fn main() -> Result<()> { ...@@ -125,14 +125,14 @@ fn main() -> Result<()> {
let only_swc_set = swc_packages let only_swc_set = swc_packages
.iter() .iter()
.map(|p| p.name.as_str()) .map(|p| p.name.as_str())
.collect::<HashSet<_>>(); .collect::<FxHashSet<_>>();
let packages = lock let packages = lock
.packages .packages
.iter() .iter()
.map(|p| (format!("{}@{}", p.name, p.version), p)) .map(|p| (format!("{}@{}", p.name, p.version), p))
.collect::<HashMap<_, _>>(); .collect::<FxHashMap<_, _>>();
let mut queue = swc_packages.clone(); let mut queue = swc_packages.clone();
let mut set = HashSet::new(); let mut set = FxHashSet::default();
while let Some(package) = queue.pop() { while let Some(package) = queue.pop() {
for dep in package.dependencies.iter() { for dep in package.dependencies.iter() {
let ident = format!("{}@{}", dep.name, dep.version); let ident = format!("{}@{}", dep.name, dep.version);
...@@ -176,7 +176,7 @@ fn main() -> Result<()> { ...@@ -176,7 +176,7 @@ fn main() -> Result<()> {
let path = sub_matches let path = sub_matches
.get_one::<String>("PATH_TO_SUMMARY_JSON") .get_one::<String>("PATH_TO_SUMMARY_JSON")
.expect("PATH_TO_SUMMARY_JSON is required"); .expect("PATH_TO_SUMMARY_JSON is required");
let bundlers: Option<HashSet<&str>> = sub_matches let bundlers: Option<FxHashSet<&str>> = sub_matches
.get_one::<String>("bundlers") .get_one::<String>("bundlers")
.map(|s| s.split(',').collect()); .map(|s| s.split(',').collect());
......
use std::{ use std::{env, fs, path::PathBuf, process, str::FromStr};
collections::{HashMap, HashSet},
env, fs,
path::PathBuf,
process,
str::FromStr,
};
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use rustc_hash::{FxHashMap, FxHashSet};
use semver::{Prerelease, Version}; use semver::{Prerelease, Version};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
...@@ -170,7 +165,7 @@ pub fn run_publish(name: &str) { ...@@ -170,7 +165,7 @@ pub fn run_publish(name: &str) {
let optional_dependencies_with_version = optional_dependencies let optional_dependencies_with_version = optional_dependencies
.into_iter() .into_iter()
.map(|name| (name, version.clone())) .map(|name| (name, version.clone()))
.collect::<HashMap<String, String>>(); .collect::<FxHashMap<String, String>>();
let pkg_json_content = let pkg_json_content =
fs::read(package_dir.join("../../package.json")).expect("Unable to read package.json"); fs::read(package_dir.join("../../package.json")).expect("Unable to read package.json");
let mut pkg_json: Value = serde_json::from_slice(&pkg_json_content).unwrap(); let mut pkg_json: Value = serde_json::from_slice(&pkg_json_content).unwrap();
...@@ -221,7 +216,7 @@ struct PackageJson { ...@@ -221,7 +216,7 @@ struct PackageJson {
path: String, path: String,
} }
pub fn run_bump(names: HashSet<String>, dry_run: bool) { pub fn run_bump(names: FxHashSet<String>, dry_run: bool) {
let workspaces_list_text = Command::program("pnpm") let workspaces_list_text = Command::program("pnpm")
.args(["ls", "-r", "--depth", "-1", "--json"]) .args(["ls", "-r", "--depth", "-1", "--json"])
.error_message("List workspaces failed") .error_message("List workspaces failed")
......
pub(crate) mod data; pub(crate) mod data;
use std::{ use std::{
collections::{hash_map::Entry, BTreeMap, HashMap}, collections::{hash_map::Entry, BTreeMap},
fs::File, fs::File,
hash::BuildHasherDefault,
path::{Path, PathBuf}, path::{Path, PathBuf},
time::{Duration, UNIX_EPOCH}, time::{Duration, UNIX_EPOCH},
}; };
...@@ -10,11 +11,14 @@ use std::{ ...@@ -10,11 +11,14 @@ use std::{
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use indexmap::IndexSet; use indexmap::IndexSet;
use rustc_hash::{FxHashMap, FxHasher};
use walkdir::WalkDir; use walkdir::WalkDir;
use self::data::Benchmark; use self::data::Benchmark;
use crate::summarize_bench::data::{BaseBenchmarks, CStats}; use crate::summarize_bench::data::{BaseBenchmarks, CStats};
type FxIndexSet<T> = IndexSet<T, BuildHasherDefault<FxHasher>>;
#[derive(Debug)] #[derive(Debug)]
struct BenchDataFile { struct BenchDataFile {
path: PathBuf, path: PathBuf,
...@@ -52,7 +56,7 @@ impl<'a> TryFrom<&'a Path> for BenchDataFile { ...@@ -52,7 +56,7 @@ impl<'a> TryFrom<&'a Path> for BenchDataFile {
} }
pub fn process_all(path: PathBuf) { pub fn process_all(path: PathBuf) {
let mut map = HashMap::new(); let mut map = FxHashMap::default();
for entry in WalkDir::new(&path) for entry in WalkDir::new(&path)
.into_iter() .into_iter()
.filter_map(Result::ok) .filter_map(Result::ok)
...@@ -63,14 +67,14 @@ pub fn process_all(path: PathBuf) { ...@@ -63,14 +67,14 @@ pub fn process_all(path: PathBuf) {
{ {
let data_file_result: Result<BenchDataFile, _> = entry.path().try_into(); let data_file_result: Result<BenchDataFile, _> = entry.path().try_into();
if let Ok(data_file) = data_file_result { if let Ok(data_file) = data_file_result {
let inner_map: &mut HashMap<_, _> = map.entry(data_file.system.clone()).or_default(); let inner_map: &mut FxHashMap<_, _> = map.entry(data_file.system.clone()).or_default();
let items: &mut Vec<BenchDataFile> = let items: &mut Vec<BenchDataFile> =
inner_map.entry(data_file.sha.clone()).or_default(); inner_map.entry(data_file.sha.clone()).or_default();
items.push(data_file); items.push(data_file);
} }
} }
for (system, inner_map) in map { for (system, inner_map) in map {
let mut latest: HashMap<std::string::String, (u64, String, Benchmark)> = HashMap::new(); let mut latest: FxHashMap<String, (u64, String, Benchmark)> = FxHashMap::default();
for (sha, data_files) in inner_map { for (sha, data_files) in inner_map {
let min_ts = data_files.iter().map(|d| d.timestamp).min().unwrap(); let min_ts = data_files.iter().map(|d| d.timestamp).min().unwrap();
let max_ts = data_files.iter().map(|d| d.timestamp).max().unwrap(); let max_ts = data_files.iter().map(|d| d.timestamp).max().unwrap();
...@@ -85,7 +89,7 @@ pub fn process_all(path: PathBuf) { ...@@ -85,7 +89,7 @@ pub fn process_all(path: PathBuf) {
data data
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mut by_name = HashMap::new(); let mut by_name = FxHashMap::default();
for (i, data) in items.iter().enumerate() { for (i, data) in items.iter().enumerate() {
for (name, bench) in data.benchmarks.iter() { for (name, bench) in data.benchmarks.iter() {
let list: &mut Vec<_> = by_name.entry(name).or_default(); let list: &mut Vec<_> = by_name.entry(name).or_default();
...@@ -143,7 +147,7 @@ pub fn process_all(path: PathBuf) { ...@@ -143,7 +147,7 @@ pub fn process_all(path: PathBuf) {
let all_benchmark_keys = items let all_benchmark_keys = items
.iter() .iter()
.flat_map(|b| b.benchmarks.keys()) .flat_map(|b| b.benchmarks.keys())
.collect::<IndexSet<_>>(); .collect::<FxIndexSet<_>>();
for key in all_benchmark_keys { for key in all_benchmark_keys {
let (ts, bench) = items let (ts, bench) = items
.iter() .iter()
......
use std::{ use std::{
collections::{BTreeMap, HashSet}, collections::BTreeMap,
fs::{self, File}, fs::{self, File},
io::BufReader, io::BufReader,
path::PathBuf, path::PathBuf,
...@@ -15,6 +15,7 @@ use plotters::{ ...@@ -15,6 +15,7 @@ use plotters::{
series::LineSeries, series::LineSeries,
style::{Color, RGBAColor, RGBColor}, style::{Color, RGBAColor, RGBColor},
}; };
use rustc_hash::FxHashSet;
use crate::summarize_bench::data::{BaseBenchmarks, CStats}; use crate::summarize_bench::data::{BaseBenchmarks, CStats};
...@@ -117,7 +118,7 @@ impl Bundler { ...@@ -117,7 +118,7 @@ impl Bundler {
} }
} }
pub fn generate(summary_path: PathBuf, filter_bundlers: Option<HashSet<&str>>) -> Result<()> { pub fn generate(summary_path: PathBuf, filter_bundlers: Option<FxHashSet<&str>>) -> Result<()> {
let summary_file = File::open(&summary_path)?; let summary_file = File::open(&summary_path)?;
let reader = BufReader::new(summary_file); let reader = BufReader::new(summary_file);
let summary: BaseBenchmarks = serde_json::from_reader(reader)?; let summary: BaseBenchmarks = serde_json::from_reader(reader)?;
...@@ -260,7 +261,7 @@ fn generate_scaling(output_path: PathBuf, by_bench: &ByBench) -> Result<()> { ...@@ -260,7 +261,7 @@ fn generate_scaling(output_path: PathBuf, by_bench: &ByBench) -> Result<()> {
for theme in THEMES { for theme in THEMES {
for (bench_name, by_bundler) in by_bench { for (bench_name, by_bundler) in by_bench {
let module_counts: HashSet<_> = by_bundler let module_counts: FxHashSet<_> = by_bundler
.values() .values()
.flat_map(|by_module_count| by_module_count.keys()) .flat_map(|by_module_count| by_module_count.keys())
.copied() .copied()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment