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

Move the typecast out of ReadRawVcFuture and into a new wrapper type #8654

Merged
merged 3 commits into from
Jul 3, 2024

Conversation

bgw
Copy link
Member

@bgw bgw commented Jul 2, 2024

Description

I noticed we were doing the typecast inside ReadRawVcFuture. This felt bad for a few reasons:

  • It's confusing that IntoFuture for Vc exposes a "raw" type to userspace. RawVc is a concept that only turbo-tasks internals and backends should deal with.

  • RawVc is the type-erased version of Vc, so it's wrong for it to do the cast. Vc should do the cast.

  • ReadRawVcFuture has a large poll method and many different values for T, so it would be ideal to avoid monomorphizing that (this seems to be a huge advantage of RawVc!), but unfortunately since this did a cast, it was being monomorphized.

This moves the casting logic and type annotations into a new ReadVcFuture type that wraps ReadRawVcFuture.

Binary Size

This is an easy-to-measure proxy metric for rustc build times. As monomorphization happens in crates that use these methods, and not those that define them, it may have an increased impact on incremental build times.

I built next-swc tarballs on Linux arm64.

Comparing stripped debug builds created with pnpm pack-next gives a 660KB or 0.3958% decrease:

-rw-r--r-- 1 bgw bgw 170752000 Jul  2 16:28 next-swc.before.tar
-rw-r--r-- 1 bgw bgw 170076160 Jul  2 16:18 next-swc.after.tar

Comparing stripped release builds created with pnpm pack-next --release gives a 320KB or 0.3049% decrease:

-rw-r--r-- 1 bgw bgw 107130880 Jul  2 16:43 next-swc.after.tar
-rw-r--r-- 1 bgw bgw 107458560 Jul  2 16:40 next-swc.before.tar

bgw added 3 commits July 2, 2024 14:07
- Fixed lots of links.

- Export `VcCast`, `VcValueTypeCast`, and `VcValueTraitCast`, as they're
  used in some type signatures, and some documentation is impossible to
  follow without it. This introduces the sealed trait pattern to
  `VcCast` to continue to strongly prevent foreign implementations.
I noticed we were doing the typecast inside `ReadRawVcFuture`. This felt
bad for a few reasons:

- It's confusing that `IntoFuture` for `Vc` exposes a "raw" type to
  userspace. `RawVc` is a concept that only turbo-tasks internals and
  backends should deal with.

- `RawVc` is the type-erased version of `Vc`, so it's wrong for it to do
  the cast. `Vc` should do the cast.

- `ReadRawVcFuture` has a large `poll` method, so it would be ideal to
  avoid monomorphizing that (this seems to be a huge advantage of
  `RawVc`!), but unfortunately since this does a cast, it must be
  monomorphized.

This moves the casting logic and type annotations into a new
`ReadVcFuture` type that wraps `ReadRawVcFuture`.
Copy link

vercel bot commented Jul 2, 2024

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

Name Status Preview Comments Updated (UTC)
rust-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2024 11:51pm
9 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Jul 2, 2024 11:51pm
examples-nonmonorepo ⬜️ Skipped (Inspect) Jul 2, 2024 11:51pm

@vercel vercel bot temporarily deployed to Preview – examples-nonmonorepo July 2, 2024 23:49 Inactive
Copy link
Member Author

bgw commented Jul 2, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bgw and the rest of your teammates on Graphite Graphite

Copy link
Contributor

github-actions bot commented Jul 2, 2024

⚠️ This change may fail to build next-swc.

Logs

error: failed to select a version for `triomphe`.
    ... required by package `hstr v0.2.8`
    ... which satisfies dependency `hstr = "^0.2.8"` (locked to 0.2.8) of package `swc_atoms v0.6.7`
    ... which satisfies dependency `swc_atoms = "^0.6.5"` (locked to 0.6.7) of package `swc_core v0.95.4`
    ... which satisfies dependency `swc_core = "^0.95.4"` (locked to 0.95.4) of package `wasm v0.0.0 (/root/actions-runner/_work/turbo/turbo/packages/next-swc/crates/wasm)`
versions that meet the requirements `^0.1.11` (locked to 0.1.11) are: 0.1.11

all possible versions conflict with previously selected packages.

  previously selected package `triomphe v0.1.13`
    ... which satisfies dependency `triomphe = "^0.1.13"` of package `turbo-tasks v0.1.0 (https://github.com/vercel/turbo?rev=3cc9ea3eeb4e683aff19a827c9c3036ffa3d511f#99d5435d)`
    ... which satisfies git dependency `turbo-tasks` (locked to 0.1.0) of package `next-build-test v0.1.0 (/root/actions-runner/_work/turbo/turbo/packages/next-swc/crates/next-build-test)`

failed to select a version for `triomphe` which could resolve this conflict

See job summary for details

Copy link
Contributor

github-actions bot commented Jul 2, 2024

🟢 Turbopack Benchmark CI successful 🟢

Thanks

@bgw bgw marked this pull request as ready for review July 2, 2024 23:54
@bgw bgw requested a review from a team as a code owner July 2, 2024 23:54
@bgw bgw requested review from arlyon, kdy1 and sokra July 2, 2024 23:55
Copy link
Contributor

github-actions bot commented Jul 2, 2024

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Turbopack Rust tests (mac/win, non-blocking)

See workflow summary for details

Base automatically changed from bgw/turbo-tasks-docs to main July 3, 2024 03:00
@sokra sokra merged commit e169340 into main Jul 3, 2024
54 of 57 checks passed
@sokra sokra deleted the bgw/vc-future branch July 3, 2024 08:01
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
…ercel/turborepo#8654)

## Description

I noticed we were doing the typecast inside `ReadRawVcFuture`. This felt
bad for a few reasons:

- It's confusing that `IntoFuture` for `Vc` exposes a "raw" type to
userspace. `RawVc` is a concept that only turbo-tasks internals and
backends should deal with.

- `RawVc` is the type-erased version of `Vc`, so it's wrong for it to do
the cast. `Vc` should do the cast.

- `ReadRawVcFuture` has a large `poll` method and many different values
for `T`, so it would be ideal to avoid monomorphizing that (this seems
to be a huge advantage of `RawVc`!), but unfortunately since this did a
cast, it was being monomorphized.

This moves the casting logic and type annotations into a new
`ReadVcFuture` type that wraps `ReadRawVcFuture`.
## Binary Size

*This is an easy-to-measure proxy metric for rustc build times. As
monomorphization happens in crates that use these methods, and not those
that define them, it may have an increased impact on incremental build
times.*

I built `next-swc` tarballs on Linux arm64.

Comparing stripped debug builds created with `pnpm pack-next` gives a
660KB or 0.3958% decrease:

```
-rw-r--r-- 1 bgw bgw 170752000 Jul  2 16:28 next-swc.before.tar
-rw-r--r-- 1 bgw bgw 170076160 Jul  2 16:18 next-swc.after.tar
```

Comparing stripped release builds created with `pnpm pack-next
--release` gives a 320KB or 0.3049% decrease:

```
-rw-r--r-- 1 bgw bgw 107130880 Jul  2 16:43 next-swc.after.tar
-rw-r--r-- 1 bgw bgw 107458560 Jul  2 16:40 next-swc.before.tar
```
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
…ercel/turborepo#8654)

## Description

I noticed we were doing the typecast inside `ReadRawVcFuture`. This felt
bad for a few reasons:

- It's confusing that `IntoFuture` for `Vc` exposes a "raw" type to
userspace. `RawVc` is a concept that only turbo-tasks internals and
backends should deal with.

- `RawVc` is the type-erased version of `Vc`, so it's wrong for it to do
the cast. `Vc` should do the cast.

- `ReadRawVcFuture` has a large `poll` method and many different values
for `T`, so it would be ideal to avoid monomorphizing that (this seems
to be a huge advantage of `RawVc`!), but unfortunately since this did a
cast, it was being monomorphized.

This moves the casting logic and type annotations into a new
`ReadVcFuture` type that wraps `ReadRawVcFuture`.
## Binary Size

*This is an easy-to-measure proxy metric for rustc build times. As
monomorphization happens in crates that use these methods, and not those
that define them, it may have an increased impact on incremental build
times.*

I built `next-swc` tarballs on Linux arm64.

Comparing stripped debug builds created with `pnpm pack-next` gives a
660KB or 0.3958% decrease:

```
-rw-r--r-- 1 bgw bgw 170752000 Jul  2 16:28 next-swc.before.tar
-rw-r--r-- 1 bgw bgw 170076160 Jul  2 16:18 next-swc.after.tar
```

Comparing stripped release builds created with `pnpm pack-next
--release` gives a 320KB or 0.3049% decrease:

```
-rw-r--r-- 1 bgw bgw 107130880 Jul  2 16:43 next-swc.after.tar
-rw-r--r-- 1 bgw bgw 107458560 Jul  2 16:40 next-swc.before.tar
```
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
…ercel/turborepo#8654)

## Description

I noticed we were doing the typecast inside `ReadRawVcFuture`. This felt
bad for a few reasons:

- It's confusing that `IntoFuture` for `Vc` exposes a "raw" type to
userspace. `RawVc` is a concept that only turbo-tasks internals and
backends should deal with.

- `RawVc` is the type-erased version of `Vc`, so it's wrong for it to do
the cast. `Vc` should do the cast.

- `ReadRawVcFuture` has a large `poll` method and many different values
for `T`, so it would be ideal to avoid monomorphizing that (this seems
to be a huge advantage of `RawVc`!), but unfortunately since this did a
cast, it was being monomorphized.

This moves the casting logic and type annotations into a new
`ReadVcFuture` type that wraps `ReadRawVcFuture`.
## Binary Size

*This is an easy-to-measure proxy metric for rustc build times. As
monomorphization happens in crates that use these methods, and not those
that define them, it may have an increased impact on incremental build
times.*

I built `next-swc` tarballs on Linux arm64.

Comparing stripped debug builds created with `pnpm pack-next` gives a
660KB or 0.3958% decrease:

```
-rw-r--r-- 1 bgw bgw 170752000 Jul  2 16:28 next-swc.before.tar
-rw-r--r-- 1 bgw bgw 170076160 Jul  2 16:18 next-swc.after.tar
```

Comparing stripped release builds created with `pnpm pack-next
--release` gives a 320KB or 0.3049% decrease:

```
-rw-r--r-- 1 bgw bgw 107130880 Jul  2 16:43 next-swc.after.tar
-rw-r--r-- 1 bgw bgw 107458560 Jul  2 16:40 next-swc.before.tar
```
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
…ercel/turborepo#8654)

## Description

I noticed we were doing the typecast inside `ReadRawVcFuture`. This felt
bad for a few reasons:

- It's confusing that `IntoFuture` for `Vc` exposes a "raw" type to
userspace. `RawVc` is a concept that only turbo-tasks internals and
backends should deal with.

- `RawVc` is the type-erased version of `Vc`, so it's wrong for it to do
the cast. `Vc` should do the cast.

- `ReadRawVcFuture` has a large `poll` method and many different values
for `T`, so it would be ideal to avoid monomorphizing that (this seems
to be a huge advantage of `RawVc`!), but unfortunately since this did a
cast, it was being monomorphized.

This moves the casting logic and type annotations into a new
`ReadVcFuture` type that wraps `ReadRawVcFuture`.
## Binary Size

*This is an easy-to-measure proxy metric for rustc build times. As
monomorphization happens in crates that use these methods, and not those
that define them, it may have an increased impact on incremental build
times.*

I built `next-swc` tarballs on Linux arm64.

Comparing stripped debug builds created with `pnpm pack-next` gives a
660KB or 0.3958% decrease:

```
-rw-r--r-- 1 bgw bgw 170752000 Jul  2 16:28 next-swc.before.tar
-rw-r--r-- 1 bgw bgw 170076160 Jul  2 16:18 next-swc.after.tar
```

Comparing stripped release builds created with `pnpm pack-next
--release` gives a 320KB or 0.3049% decrease:

```
-rw-r--r-- 1 bgw bgw 107130880 Jul  2 16:43 next-swc.after.tar
-rw-r--r-- 1 bgw bgw 107458560 Jul  2 16:40 next-swc.before.tar
```
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.

3 participants