mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## What? Remove `#[turbo_tasks::function]` from all methods on the `Issue` value_trait, following the same pattern as #92593 which did the same for `ValueDebug`. The `Issue` trait previously had 8 methods decorated with `#[turbo_tasks::function]`, which caused the turbo-tasks machinery to generate `NativeFunction` statics, task registration, vtable entries, and scheduling/caching infrastructure for each method on each of the ~48 `impl Issue for` types in the codebase — most of which are trivially synchronous (returning a constant string, enum variant, or stored struct field). ## How? - Change all 8 `Issue` trait methods to plain methods. Methods that are always synchronous become direct return-type methods (`severity`, `stage`, `source`, `documentation_link`). Methods that are genuinely async on at least one impl use `Pin<Box<dyn Future<Output = Result<T>> + Send + '_>>` for object safety. - Callers that need to invoke trait methods on a `Vc<Box<dyn Issue>>` use `issue.into_trait_ref().await?` to get a `TraitRef<Box<dyn Issue>>` and call methods directly on that. - `PlainIssue::from_issue` (the sole hot caller that materializes all fields) resolves one `trait_ref` and calls all methods on it, similar to the `ValueDebug` pattern. - `ResolvingIssueWithLocation` (which wraps an inner `ResolvedVc<Box<dyn Issue>>`) eagerly copies `severity`, `stage`, `documentation_link`, and `source` at construction time rather than delegating async calls to the inner issue. - Delete `OptionIssueSource` and `OptionStyledString` wrapper types, which existed solely as `Vc<T>` return type wrappers for the old turbo-tasks methods. ## Tradeoffs **Lost per-call caching:** Previously each `Issue` method was a turbo-tasks task, so results were cached per `(Vc<Issue>, method)`. In practice this caching was useless — issues are emitted once and their fields read once by `PlainIssue::from_issue`, so there was never a second call to hit the cache. The only real cost is that `IssueFilter::matches` previously cached per `(filter, issue)` pair; that caching is preserved because `matches` itself remains a `#[turbo_tasks::function]` and now calls `into_trait_ref().await?` once at the top. **`ResolvingIssueWithLocation` eagerly reads inner fields:** Instead of lazily delegating to the inner issue, `stage` and `documentation_link` are copied at construction. This is a minor semantic change (the values are snapshotted rather than live), but in practice these fields are always constant values so it makes no difference. ## Binary size impact (darwin-arm64, compared against #92593) | Metric | #92593 baseline | This PR | Delta | |---|---|---|---| | Unstripped dylib | 124.6 MB | 124.0 MB | **-0.6 MB (-0.5%)** | | Stripped | 84.7 MB | 84.4 MB | **-0.3 MB (-0.4%)** | | Stripped + gzip (npm) | 29.2 MB | 29.1 MB | **-0.1 MB (-0.3%)** | Smaller savings than `ValueDebug` (~2.5 MB stripped) because there are ~48 `Issue` impls vs. one `ValueDebug` impl per every `#[turbo_tasks::value]` type. But real and cumulative. <!-- NEXT_JS_LLM_PR -->
69 lines
2.9 KiB
TOML
69 lines
2.9 KiB
TOML
[package]
|
|
name = "turbo-tasks-fetch"
|
|
version = "0.1.0"
|
|
description = "TBD"
|
|
license = "MIT"
|
|
edition = "2024"
|
|
|
|
[lib]
|
|
bench = false
|
|
|
|
[lints]
|
|
workspace = true
|
|
|
|
[dependencies]
|
|
anyhow = { workspace = true }
|
|
async-trait = { workspace = true }
|
|
quick_cache = { workspace = true }
|
|
serde = { workspace = true }
|
|
tokio = { workspace = true }
|
|
turbo-rcstr = { workspace = true }
|
|
turbo-tasks = { workspace = true }
|
|
turbo-tasks-fs = { workspace = true }
|
|
turbopack-core = { workspace = true }
|
|
|
|
# Enable specific tls features per-target.
|
|
#
|
|
# Be careful when selecting tls backend. If you must verify ALL build targets of
|
|
# next-swc to ensure it works. next-swc have various platforms, some don't
|
|
# support native-tls (using openssl-sys) and some aren't buildable with rustls.
|
|
#
|
|
# The TLS backend used must match with the construction of `request::Client` in
|
|
# `src/client.rs`.
|
|
|
|
# On macOS, use the default rustls configuration (uses aws-lc-rs).
|
|
[target.'cfg(target_os = "macos")'.dependencies]
|
|
reqwest = { workspace = true, features = ["rustls"] }
|
|
|
|
# On Linux (all architectures) and Windows x86-64, use ring for rustls.
|
|
# - Linux: aws-lc-rs has cross-compilation issues in our CI:
|
|
# https://github.com/aws/aws-lc-rs/issues/673
|
|
# - On Linux, linking with the native SSL library can be distro-dependent, so
|
|
# it's easier for us to statically link ring or aws-lc-rs.
|
|
# - Windows: aws-lc-sys requires NASM and CMake which we don't have installed in
|
|
# CI, and would complicate the development environment setup. We could
|
|
# possibly switch to always using `native-tls` on Windows in the future.
|
|
[target.'cfg(any(target_os = "linux", all(windows, not(target_arch = "aarch64"))))'.dependencies]
|
|
reqwest = { workspace = true, features = ["rustls-no-provider"] }
|
|
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
|
|
|
|
# On Linux, we need to add webpki-roots, in case the user is building a bare-bones docker image that
|
|
# does not contain any root certs (e.g. `oven/bun:slim`). See footnote #2 here:
|
|
# https://github.com/rustls/rustls-platform-verifier/tree/93f729c6309680486d33f982e3ba3c42b976f774?tab=readme-ov-file#user-content-fn-3-7402e7116652999a2e8c2860b94080eb
|
|
#
|
|
# It would be more ideal to use the smaller `webpki-roots` crate instead of `webpki-root-certs`, but
|
|
# API limitations of reqwest require us to get the full certificate:
|
|
# https://github.com/seanmonstar/reqwest/discussions/2906#discussioncomment-15483148
|
|
[target.'cfg(target_os = "linux")'.dependencies]
|
|
webpki-root-certs = "1"
|
|
|
|
# On Windows ARM64, use native-tls because rustls with ring has build issues.
|
|
[target.'cfg(all(windows, target_arch = "aarch64"))'.dependencies]
|
|
reqwest = { workspace = true, features = ["native-tls"] }
|
|
|
|
[dev-dependencies]
|
|
mockito = { version = "1.7.0", default-features = false }
|
|
tokio = { workspace = true, features = ["full"] }
|
|
turbo-tasks-testing = { workspace = true }
|
|
turbo-tasks-backend = { workspace = true }
|