Skip to content

Commit

Permalink
perf(turbopack): Update rustc-hash from 1.1.0 to 2.1.0 (#75531)
Browse files Browse the repository at this point in the history
> Replace hash with faster and better finalized hash. This replaces the previous "fxhash" algorithm originating in Firefox with a custom hasher designed and implemented by Orson Peters (orlp). It was measured to have slightly better performance for rustc, has better theoretical properties and also includes a significantly better string hasher.

https://github.com/rust-lang/rustc-hash/blob/master/CHANGELOG.md

# Benchmarks

Any perf difference either way is too small to be easily measured. Benchmarks here technically show a tiny regression, but that's well within the run-to-run variance I've observed.

## rustc-hash 1.1.0

```
$ 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.736 s ±  0.294 s    [User: 122.811 s, System: 15.908 s]
  Range (min … max):   26.340 s … 27.165 s    5 runs
```

## rustc-hash 2.1.0

```
$ 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.206 s ±  0.540 s    [User: 126.145 s, System: 15.958 s]
  Range (min … max):   26.543 s … 27.894 s    5 runs
```
  • Loading branch information
bgw authored Feb 4, 2025
1 parent a949068 commit fd27e58
Show file tree
Hide file tree
Showing 36 changed files with 329 additions and 320 deletions.
33 changes: 17 additions & 16 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ rayon = "1.10.0"
regex = "1.10.6"
reqwest = { version = "=0.11.17", default-features = false }
rstest = "0.16.0"
rustc-hash = "1.1.0"
rustc-hash = "2.1.0"
semver = "1.0.16"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.138"
Expand All @@ -201,6 +201,7 @@ smallvec = { version = "1.13.1", features = [
] }
sourcemap = "9.0.0"
strsim = "0.11.1"
swc-rustc-hash = { package = "rustc-hash", version = "1.1.0" } # used with swc
syn = "1.0.107"
tempfile = "3.3.0"
thread_local = "1.1.8"
Expand Down
1 change: 1 addition & 0 deletions crates/next-custom-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ once_cell = { workspace = true }
pathdiff = { workspace = true }
regex = "1.5"
rustc-hash = { workspace = true }
swc-rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, features = ["preserve_order"] }
sha1 = "0.10.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct State {

extra_stmts: Vec<Stmt>,

rename_map: FxHashMap<Id, Id>,
rename_map: swc_rustc_hash::FxHashMap<Id, Id>,

/// Ignored identifiers for `obj` of [MemberExpr].
ignored: FxHashSet<Id>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Analyzer<'_> {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub(crate) enum Key {
ModuleEvaluation,
Export(RcStr),
Expand Down
10 changes: 8 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/tree_shake/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Write, hash::Hash, path::PathBuf, sync::Arc};
use std::{collections::BTreeMap, fmt::Write, hash::Hash, path::PathBuf, sync::Arc};

use anyhow::Error;
use serde::Deserialize;
Expand Down Expand Up @@ -192,7 +192,13 @@ fn run(input: PathBuf) {
..
} = g.split_module(&[], analyzer.items);

writeln!(s, "# Entrypoints\n\n```\n{:#?}\n```\n\n", entrypoints).unwrap();
writeln!(
s,
"# Entrypoints\n\n```\n{:#?}\n```\n\n",
// sort entrypoints for the snapshot
entrypoints.iter().collect::<BTreeMap<_, _>>(),
)
.unwrap();

if !skip_parts {
writeln!(s, "# Modules ({})", if is_debug { "dev" } else { "prod" }).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,16 @@ graph TD
Export(
"external1",
): 10,
Exports: 14,
Export(
"external2",
): 11,
Export(
"foo",
): 13,
Export(
"foobar",
): 11,
Export(
"external2",
): 11,
Exports: 14,
}
```

Expand Down Expand Up @@ -612,16 +612,16 @@ import "__TURBOPACK_PART__" assert {
Export(
"external1",
): 9,
Exports: 12,
Export(
"external2",
): 10,
Export(
"foo",
): 3,
Export(
"foobar",
): 11,
Export(
"external2",
): 10,
Exports: 12,
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,16 @@ graph TD
Export(
"external1",
): 0,
Exports: 14,
Export(
"external2",
): 11,
Export(
"foo",
): 13,
Export(
"foobar",
): 11,
Export(
"external2",
): 11,
Exports: 14,
}
```

Expand Down Expand Up @@ -631,16 +631,16 @@ import "__TURBOPACK_PART__" assert {
Export(
"external1",
): 0,
Exports: 12,
Export(
"external2",
): 10,
Export(
"foo",
): 4,
Export(
"foobar",
): 11,
Export(
"external2",
): 10,
Exports: 12,
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ graph TD
{
ModuleEvaluation: 12,
Export(
"serverHooks",
): 11,
"originalPathname",
): 10,
Export(
"patchFetch",
): 11,
Expand All @@ -375,13 +375,13 @@ graph TD
Export(
"routeModule",
): 14,
Exports: 15,
Export(
"workAsyncStorage",
"serverHooks",
): 11,
Export(
"originalPathname",
): 10,
"workAsyncStorage",
): 11,
Exports: 15,
}
```

Expand Down Expand Up @@ -608,25 +608,25 @@ import "__TURBOPACK_PART__" assert {
```
{
ModuleEvaluation: 12,
Export(
"originalPathname",
): 10,
Export(
"patchFetch",
): 11,
Export(
"requestAsyncStorage",
): 13,
Export(
"serverHooks",
): 15,
Export(
"routeModule",
): 14,
Exports: 17,
Export(
"serverHooks",
): 15,
Export(
"workAsyncStorage",
): 16,
Export(
"originalPathname",
): 10,
Exports: 17,
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ graph TD
```
{
ModuleEvaluation: 2,
Exports: 3,
Export(
"b",
): 1,
Export(
"a",
): 0,
Export(
"b",
): 1,
Exports: 3,
}
```

Expand Down Expand Up @@ -143,13 +143,13 @@ export { b } from "__TURBOPACK_PART__" assert {
```
{
ModuleEvaluation: 2,
Exports: 3,
Export(
"b",
): 1,
Export(
"a",
): 0,
Export(
"b",
): 1,
Exports: 3,
}
```

Expand Down
Loading

0 comments on commit fd27e58

Please sign in to comment.