Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor asset identification #3999

Merged
merged 7 commits into from
Mar 1, 2023
Merged

refactor asset identification #3999

merged 7 commits into from
Mar 1, 2023

Conversation

sokra
Copy link
Member

@sokra sokra commented Feb 28, 2023

  • add Asset::ident() as unique identifier of an Asset
  • add ChunkItem::ident() instead of ChunkItem::to_string() (ValueToString)
  • base chunk_path on AssetIdent instead of path only

Motivation:

We want to get rid of the import "." in favor of inner assets. When doing this we no longer need to place virtual assets below the actual file path and they can stay in their original path. But placing virtual assets below the actual asset also made the Asset::path unique, which would no longer be the case after using inner assets. Some parts of the code base relied on Asset::path being unique (e. g. module ids and chunk paths). But actually we never guaranteed that to be unique.
After this PR Asset::ident is intended to be unique and allow to carry more information than only the path:

  • Query string (module?query)
  • Fragment (module#fragment)
  • Asset (additional wrapped assets by key value pairs)
  • Modifiers (additional transformations applied on the module, e. g. chunks, client chunks)
  • In future: Part (select a subpart of the module, e. g. only export abc, or the module evaluation, or some internal part)

@vercel
Copy link

vercel bot commented Feb 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-basic-web 🔄 Building (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-cra-web 🔄 Building (Inspect) Mar 1, 2023 at 8:08AM (UTC)
8 Ignored Deployments
Name Status Preview Comments Updated
examples-designsystem-docs ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-tailwind-web ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Mar 1, 2023 at 8:08AM (UTC)
turbo-site ⬜️ Ignored (Inspect) Visit Preview Mar 1, 2023 at 8:08AM (UTC)

crates/turbopack-core/src/ident.rs Outdated Show resolved Hide resolved
crates/turbopack-core/src/asset.rs Outdated Show resolved Hide resolved
for param in ident.params.iter() {
match *param {
AssetParam::Query(query) => {
0_u8.deterministic_hash(&mut hasher);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a DeterministicHash derive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work here well since it is async. We would need a AsyncDeterministicHash where deterministic_hash is an async method. That's a lot work...

crates/turbopack-core/src/chunk/mod.rs Outdated Show resolved Hide resolved
crates/turbopack-css/src/chunk/mod.rs Outdated Show resolved Hide resolved
crates/turbopack-css/src/chunk/mod.rs Outdated Show resolved Hide resolved
crates/turbopack-css/src/chunk/mod.rs Outdated Show resolved Hide resolved
crates/turbopack-css/src/references/url.rs Outdated Show resolved Hide resolved
crates/turbopack-ecmascript/src/chunk/mod.rs Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

Benchmark for e9524fd

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 12.89ms ± 0.07ms 12.78ms ± 0.13ms -0.86%
bench_hmr_to_commit/Turbopack RCC/1000 modules 15.30ms ± 0.16ms 15.52ms ± 0.15ms +1.45%
bench_hmr_to_commit/Turbopack RSC/1000 modules 542.01ms ± 0.99ms 539.18ms ± 1.63ms -0.52%
bench_hmr_to_commit/Turbopack SSR/1000 modules 12.70ms ± 0.13ms 12.84ms ± 0.10ms +1.13%
bench_hmr_to_eval/Turbopack CSR/1000 modules 11.67ms ± 0.10ms 11.60ms ± 0.15ms -0.62%
bench_hmr_to_eval/Turbopack RCC/1000 modules 14.40ms ± 0.09ms 14.66ms ± 0.19ms +1.86%
bench_hmr_to_eval/Turbopack SSR/1000 modules 11.77ms ± 0.08ms 11.70ms ± 0.13ms -0.63%
bench_hydration/Turbopack RCC/1000 modules 4039.21ms ± 19.17ms 4049.99ms ± 10.52ms +0.27%
bench_hydration/Turbopack RSC/1000 modules 3668.88ms ± 15.43ms 3697.65ms ± 10.28ms +0.78%
bench_hydration/Turbopack SSR/1000 modules 3551.88ms ± 14.30ms 3578.69ms ± 12.24ms +0.75%
bench_startup/Turbopack CSR/1000 modules 2721.90ms ± 4.63ms 2705.61ms ± 12.13ms -0.60%
bench_startup/Turbopack RCC/1000 modules 2495.21ms ± 10.99ms 2515.30ms ± 8.85ms +0.81%
bench_startup/Turbopack RSC/1000 modules 2414.58ms ± 9.18ms 2396.02ms ± 8.52ms -0.77%
bench_startup/Turbopack SSR/1000 modules 2176.22ms ± 5.36ms 2191.21ms ± 5.68ms +0.69%

@github-actions
Copy link
Contributor

Benchmark for b370524

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack RCC/1000 modules 16.57ms ± 0.25ms 15.52ms ± 0.17ms -6.35% -1.27%
bench_hydration/Turbopack SSR/1000 modules 3539.39ms ± 12.87ms 3492.67ms ± 9.27ms -1.32% -0.07%
bench_startup/Turbopack RSC/1000 modules 2398.17ms ± 7.04ms 2342.05ms ± 14.71ms -2.34% -0.53%
bench_startup/Turbopack SSR/1000 modules 2066.77ms ± 4.02ms 2107.96ms ± 6.30ms +1.99% +0.99%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 12.40ms ± 0.12ms 12.34ms ± 0.17ms -0.49%
bench_hmr_to_commit/Turbopack RCC/1000 modules 16.57ms ± 0.25ms 15.52ms ± 0.17ms -6.35% -1.27%
bench_hmr_to_commit/Turbopack RSC/1000 modules 515.36ms ± 2.76ms 516.66ms ± 2.28ms +0.25%
bench_hmr_to_commit/Turbopack SSR/1000 modules 12.50ms ± 0.09ms 12.79ms ± 0.18ms +2.31%
bench_hmr_to_eval/Turbopack CSR/1000 modules 11.81ms ± 0.13ms 12.04ms ± 0.10ms +1.92%
bench_hmr_to_eval/Turbopack RCC/1000 modules 14.89ms ± 0.38ms 14.39ms ± 0.21ms -3.36%
bench_hmr_to_eval/Turbopack SSR/1000 modules 11.32ms ± 0.11ms 10.93ms ± 0.10ms -3.41%
bench_hydration/Turbopack RCC/1000 modules 4124.94ms ± 17.51ms 4061.64ms ± 21.80ms -1.53%
bench_hydration/Turbopack RSC/1000 modules 3652.34ms ± 5.57ms 3621.50ms ± 15.05ms -0.84%
bench_hydration/Turbopack SSR/1000 modules 3539.39ms ± 12.87ms 3492.67ms ± 9.27ms -1.32% -0.07%
bench_startup/Turbopack CSR/1000 modules 2599.74ms ± 4.73ms 2594.76ms ± 9.51ms -0.19%
bench_startup/Turbopack RCC/1000 modules 2465.47ms ± 6.60ms 2452.86ms ± 7.32ms -0.51%
bench_startup/Turbopack RSC/1000 modules 2398.17ms ± 7.04ms 2342.05ms ± 14.71ms -2.34% -0.53%
bench_startup/Turbopack SSR/1000 modules 2066.77ms ± 4.02ms 2107.96ms ± 6.30ms +1.99% +0.99%

@github-actions
Copy link
Contributor

github-actions bot commented Feb 28, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Formatting

See workflow summary for details

@sokra sokra mentioned this pull request Mar 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

Benchmark for 471bfb8

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack RSC/1000 modules 495.67ms ± 1.23ms 507.20ms ± 1.52ms +2.33% +1.21%
bench_startup/Turbopack SSR/1000 modules 2027.26ms ± 2.03ms 2046.70ms ± 2.32ms +0.96% +0.53%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 9045.72µs ± 55.83µs 8992.02µs ± 53.69µs -0.59%
bench_hmr_to_commit/Turbopack RCC/1000 modules 12.85ms ± 0.22ms 12.73ms ± 0.23ms -0.92%
bench_hmr_to_commit/Turbopack RSC/1000 modules 495.67ms ± 1.23ms 507.20ms ± 1.52ms +2.33% +1.21%
bench_hmr_to_commit/Turbopack SSR/1000 modules 9183.88µs ± 30.19µs 9189.89µs ± 36.66µs +0.07%
bench_hmr_to_eval/Turbopack CSR/1000 modules 8143.65µs ± 57.23µs 8317.98µs ± 33.33µs +2.14%
bench_hmr_to_eval/Turbopack RCC/1000 modules 11.93ms ± 0.09ms 11.61ms ± 0.27ms -2.69%
bench_hmr_to_eval/Turbopack SSR/1000 modules 8117.79µs ± 28.09µs 8198.31µs ± 65.44µs +0.99%
bench_hydration/Turbopack RCC/1000 modules 3781.28ms ± 15.86ms 3772.39ms ± 11.22ms -0.23%
bench_hydration/Turbopack RSC/1000 modules 3414.04ms ± 14.00ms 3418.36ms ± 16.32ms +0.13%
bench_hydration/Turbopack SSR/1000 modules 3283.23ms ± 10.90ms 3322.28ms ± 10.39ms +1.19%
bench_startup/Turbopack CSR/1000 modules 2535.40ms ± 6.62ms 2547.02ms ± 6.66ms +0.46%
bench_startup/Turbopack RCC/1000 modules 2316.74ms ± 7.44ms 2308.30ms ± 5.03ms -0.36%
bench_startup/Turbopack RSC/1000 modules 2274.66ms ± 10.73ms 2273.30ms ± 16.83ms -0.06%
bench_startup/Turbopack SSR/1000 modules 2027.26ms ± 2.03ms 2046.70ms ± 2.32ms +0.96% +0.53%

add ChunkItem::ident() instead of ChunkItem::to_string()

base chunk_path on AssetIdent instead of path only
make AssetIdent having an identity
@sokra sokra force-pushed the sokra/refactor-asset-ident branch from aff7e79 to 51b3b69 Compare March 1, 2023 08:07
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

Benchmark for a7827ce

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack RCC/1000 modules 13.02ms ± 0.12ms 13.51ms ± 0.10ms +3.75% +0.35%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7565.22µs ± 34.22µs 7440.81µs ± 18.57µs -1.64% -0.25%
bench_startup/Turbopack CSR/1000 modules 2485.26ms ± 6.06ms 2518.58ms ± 9.06ms +1.34% +0.12%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8506.53µs ± 47.76µs 8540.87µs ± 50.59µs +0.40%
bench_hmr_to_commit/Turbopack RCC/1000 modules 13.02ms ± 0.12ms 13.51ms ± 0.10ms +3.75% +0.35%
bench_hmr_to_commit/Turbopack RSC/1000 modules 481.69ms ± 1.13ms 486.26ms ± 2.05ms +0.95%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8710.68µs ± 37.15µs 8722.54µs ± 81.84µs +0.14%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7565.22µs ± 34.22µs 7440.81µs ± 18.57µs -1.64% -0.25%
bench_hmr_to_eval/Turbopack RCC/1000 modules 12.23ms ± 0.06ms 11.89ms ± 0.24ms -2.80%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7598.23µs ± 51.06µs 7695.01µs ± 81.24µs +1.27%
bench_hydration/Turbopack RCC/1000 modules 3713.80ms ± 6.95ms 3725.92ms ± 9.26ms +0.33%
bench_hydration/Turbopack RSC/1000 modules 3406.28ms ± 12.25ms 3398.98ms ± 14.61ms -0.21%
bench_hydration/Turbopack SSR/1000 modules 3270.71ms ± 10.07ms 3287.92ms ± 9.01ms +0.53%
bench_startup/Turbopack CSR/1000 modules 2485.26ms ± 6.06ms 2518.58ms ± 9.06ms +1.34% +0.12%
bench_startup/Turbopack RCC/1000 modules 2281.63ms ± 8.46ms 2281.93ms ± 7.01ms +0.01%
bench_startup/Turbopack RSC/1000 modules 2227.17ms ± 8.25ms 2215.51ms ± 9.36ms -0.52%
bench_startup/Turbopack SSR/1000 modules 2005.28ms ± 3.47ms 2013.42ms ± 1.68ms +0.41%

@sokra sokra marked this pull request as ready for review March 1, 2023 09:52
@sokra sokra requested a review from a team as a code owner March 1, 2023 09:52
@sokra sokra requested a review from alexkirsz March 1, 2023 09:53

"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js/manifest-loader.js": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => {
"[project]/crates/turbopack-tests/tests/snapshot/basic/async_chunk/input/import.js (ecmascript, manifest chunk, loader)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better.

@sokra sokra merged commit 683a761 into main Mar 1, 2023
@sokra sokra deleted the sokra/refactor-asset-ident branch March 1, 2023 10:11
sokra added a commit that referenced this pull request Mar 2, 2023
### Description

* get rid of attached filesystem for our embedded modules
* get rid of import "." in favor of inner assets

depends on #3999

### Testing Instructions

existing tests

<!--
  When the below is checked (default) our PR bot will automatically
  assign labels to your PR based on the content to help the team
  organize and review it faster.
-->

[X] Auto label
ijjk added a commit to vercel/next.js that referenced this pull request Mar 2, 2023
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
* add Asset::ident() as unique identifier of an Asset
* add ChunkItem::ident() instead of ChunkItem::to_string()
(ValueToString)
* base `chunk_path` on AssetIdent instead of path only

Motivation:

We want to get rid of the `import "."` in favor of inner assets. When
doing this we no longer need to place virtual assets below the actual
file path and they can stay in their original path. But placing virtual
assets below the actual asset also made the `Asset::path` unique, which
would no longer be the case after using inner assets. Some parts of the
code base relied on `Asset::path` being unique (e. g. module ids and
chunk paths). But actually we never guaranteed that to be unique.
After this PR `Asset::ident` is intended to be unique and allow to carry
more information than only the path:
* Query string (`module?query`)
* Fragment (`module#fragment`)
* Asset (additional wrapped assets by key value pairs)
* Modifiers (additional transformations applied on the module, e. g.
`chunks`, `client chunks`)
* In future: Part (select a subpart of the module, e. g. only export
abc, or the module evaluation, or some internal part)
jridgewell pushed a commit to vercel/next.js that referenced this pull request Mar 10, 2023
### Description

* get rid of attached filesystem for our embedded modules
* get rid of import "." in favor of inner assets

depends on vercel/turbo#3999

### Testing Instructions

existing tests

<!--
  When the below is checked (default) our PR bot will automatically
  assign labels to your PR based on the content to help the team
  organize and review it faster.
-->

[X] Auto label
sokra added a commit to vercel/next.js that referenced this pull request Mar 13, 2023
* add Asset::ident() as unique identifier of an Asset
* add ChunkItem::ident() instead of ChunkItem::to_string()
(ValueToString)
* base `chunk_path` on AssetIdent instead of path only

Motivation:

We want to get rid of the `import "."` in favor of inner assets. When
doing this we no longer need to place virtual assets below the actual
file path and they can stay in their original path. But placing virtual
assets below the actual asset also made the `Asset::path` unique, which
would no longer be the case after using inner assets. Some parts of the
code base relied on `Asset::path` being unique (e. g. module ids and
chunk paths). But actually we never guaranteed that to be unique.
After this PR `Asset::ident` is intended to be unique and allow to carry
more information than only the path:
* Query string (`module?query`)
* Fragment (`module#fragment`)
* Asset (additional wrapped assets by key value pairs)
* Modifiers (additional transformations applied on the module, e. g.
`chunks`, `client chunks`)
* In future: Part (select a subpart of the module, e. g. only export
abc, or the module evaluation, or some internal part)
sokra added a commit to vercel/next.js that referenced this pull request Mar 13, 2023
### Description

* get rid of attached filesystem for our embedded modules
* get rid of import "." in favor of inner assets

depends on vercel/turbo#3999

### Testing Instructions

existing tests

<!--
  When the below is checked (default) our PR bot will automatically
  assign labels to your PR based on the content to help the team
  organize and review it faster.
-->

[X] Auto label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants