Repository navigation
perf(ts): add type views for type-only actions - #404
Conversation
Each store target declares a view of its tree with the files TypeScript's resolution reads, at the same path under node_modules.types/, with twins of the edge, hoist and importer links. TsEmit, TsgoCheck, TsgoDeclare and TsLint stage the views; a TsLint whose lint configuration names a node_modules, and runtime actions, stage the trees. --//ts:type_views=false restores the trees.
d6d19e8 to
defa22a
Compare
types_path took only paths below node_modules/, and the public hoist's directory is node_modules itself, so a lockfile that hoists a workspace member publicly failed analysis.
aherrmann-lov
left a comment
There was a problem hiding this comment.
The benchmark predates a Lovable lint change that turns views off for TsLint, so we don't know this PR's effect on Lovable yet. Please re-run the benchmark against current Lovable before we bump.
Why. TsLint stages views only when the lint configuration's data names no node_modules. Lovable's ts.lint names //:oxlint_config_node_modules since lovablelabs/lovable#176469, merged 2026-11-26. Before that, its data had no node_modules, which is the configuration the table measures. On today's Lovable, TsgoCheck stages views and TsLint stages the trees, the mix this PR's description measured at about 20% slower for the pair than views off.
Evidence. bazel aquery of //packages/emails:emails in Lovable at origin/main, at the current pin and with --override_module=rules_typescript= this PR's head (ef10012e):
| Current pin | This PR | |
|---|---|---|
| TsgoCheck npm inputs | 192 trees and links | 198 views and view links |
| TsLint npm inputs | 213 trees and links | 213 trees and links |
So the −32% TsLint input files and the −14% TsgoCheck + TsLint time can't come from this code on Lovable today. The result may even be a slowdown.
Options. Either keep the program's npm closure on views and stage only lint.data's packages as trees, so TsgoCheck and TsLint share an input root again, or change Lovable so its oxlint configuration doesn't need a node_modules in data. Either way, the numbers in the description need a fresh run.
via Claude Code, Claude Opus 5.5
aherrmann-lov
left a comment
There was a problem hiding this comment.
What is --//ts:type_views for? The answer decides its shape.
The off path is untested. Views are the default, and nothing in tests/, CI or the .bazelrc files sets --//ts:type_views=false. So the trees path for type actions, which the flag promises to restore, runs nowhere, and it will rot unnoticed. If we keep the flag, please add at least one test lane or analysis test that runs with it off.
As a build-wide switch, it is a coarse escape hatch. scope = "target" resets the flag on exec transitions; it is still one value per build. If one package's resolution needs a file its view drops, the only fix is views off everywhere, which gives up the whole saving. That is fine for an A/B benchmark or an emergency rollback, but not as a per-package escape hatch.
Please don't make it per target with a transition. A transition on this flag puts the transitioned subgraph in its own configuration, so every npm store tree, view and link under it is analyzed and built a second time, though the stores never read the flag.
If per-target control is the goal, an attribute works. I tried a type_views = attr.bool(default = True) on ts_compile/ts_test, ANDed into the existing check at ts/private/rules/ts_compile.bzl:632 (two lines). In Lovable, with type_views = False on //packages/applocal-mcp:applocal-mcp:
| Target | TsgoCheck | TsLint |
|---|---|---|
:applocal-mcp (type_views = False) |
trees | trees |
:applocal-mcp_test__native_program (depends on it) |
views | trees (see the lint comment) |
All 2,585 target-config stores in the test's closure stay in one configuration; the only other configuration holds the 7 exec-config lint and format tool stores, as without the attribute. bazel build of both targets, validations included, passes. Each program already falls back on its own (None not in dep_npm_view_sets), so one target's choice does not change what its dependents stage.
Analysis cost, for reference. In Lovable (bazel build --nobuild //web/... //packages/..., fresh server, this PR's base against its head, two runs each), retained heap after GC grows from 1,072 MB to 1,088 MB (+1.4%). The action graph grows from 67,855 to 91,410 actions: 5,200 NpmTypeView and 18,355 more UnresolvedSymlink. I saw no analysis-time regression. Declaring views whatever the flag says is cheap enough not to gate.
via Claude Code, Claude Opus 5.5
The lint configuration's data links are laid over the root importer's twin with -runtime_link, so its imports run from the trees while the program stays on views and shares TsgoCheck's input root. Add a type_views attribute for a per-program escape hatch, and test the trees path, by attribute and by flag.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9e5975e. Configure here.
The chain's last importer is laid at the program root's node_modules, so its runtime links go there, not at their bin-relative path.
|
@aherrmann-lov thanks, both points held. Changes are in Lint on today's Lovable. Right: since lovablelabs/lovable#176469 TsLint fell back to the trees, the slow mix. I took your first option. TsLint now always stages the views, and each importer link the lint configuration's Fresh benchmark on Lovable The flag. I kept |
aherrmann-lov
left a comment
There was a problem hiding this comment.
Both points are addressed. Approving.
Lint. On Lovable main, //packages/emails:emails's TsLint now stages the same 198 view artifacts as its TsgoCheck, plus 21 tree artifacts for @cloudflare/oxlint-config's closure through -runtime_link. Before, it staged 213 trees. The fresh off/on/off run on 1,058 programs replaces the stale numbers.
Flag and attribute. The build-wide flag for comparisons and rollback, the type_views attribute as the per-target escape hatch with no transition, and the two analysis tests for the off path settle my questions.
Checked. The four new and changed tsaction tests pass. The 38 other tsaction failures under a plain go test are the same set on main (25fb6adc), so they come from running outside Bazel. CI is green apart from the macOS unit-test lane, still running.
Nit, non-blocking. In ts/tools/tsaction/tsgo.go, linkAt's doc comment ("linkAt links the exec root's rel into root at rel, its directories real.") now opens typeViewHoles' doc comment, and linkAt has none. Moving that line back above func linkAt fixes it.
via Claude Code, Claude Opus 5.5
|
@aherrmann-lov fixed the nit in 1f940dc: |

TsEmit, TsgoCheck, TsgoDeclare and TsLint now stage a type view of each npm package, the files TypeScript's resolution reads, instead of the whole tree. Over the lovable monorepo's 1,058 programs at today's
main, TsgoCheck and TsLint stage a third fewer files and spend 10% less worker time, with every emitted declaration byte-identical. Runtime actions keep the trees.type_views = Falseon a target, or--//ts:type_views=falsefor a build, restores them for the type actions too.Claude Opus 5.5, low
Why. A type check reads
package.json, JSON,.tsand declarations. It never opens a source map, a stylesheet, an image, or a.jswith its declaration beside it, yet each TsgoCheck and TsLint stages all of them for every package in its closure. On the lovable monorepo's web programs those were about a third of the input files, and every one is a link a Buildbarn worker makes for every action.What a view holds.
tsaction typeviewcopies a store tree'spackage.json, every.json,.ts,.tsx,.mtsand.cts(declarations included), and JavaScript only where TypeScript tries no declaration in its place:.jsand.jsxwithout a.d.ts,.mjswithout a.d.mts,.cjswithout a.d.cts. OneNpmTypeViewaction per store target writes it. Bazel builds it only when a type action stages it.Layout. Every
node_modules/path gets a twin at the same path undernode_modules.types/, so the views' lookup order is the trees':flowchart LR subgraph full["runtime actions"] I1["web/node_modules/zod"] --> T1["node_modules/.pnpm/zod@3/node_modules/zod"] end subgraph views["type actions"] I2["web/node_modules.types/node_modules/zod"] --> T2["node_modules.types/node_modules/.pnpm/zod@3/node_modules/zod"] end T1 -- "NpmTypeView" --> T2Edge links, hoist links (
node_modules.types/node_modules/.pnpm/node_modules) and importer links each have a twin into the views.NpmStoreInfo.view/view_links/view_transitive,NpmLinkInfo.view_link,NpmHoistInfo.view_membersandTsInfo.npm_view_filescarry them.compile_programhands the type actionsnpm_view_filesand the importers'node_modules.types/node_modulesdirectories, and the ownership manifest names the views.tsaction. Three changes, all only when an importer is a twin:
importerDirmaps<dir>/node_modules.types/node_modulesto<dir>.typesentries by walking up from there. So the program root'sbazel-outbecomes real directories down to each importer'snode_modules, linked to its twin, with every other entry linked as before. Without this, everytypes: ["node"]fails with TS2688.//npm-packages/slides's test compilestemplates/slides_tanstack_tssources. On views, the root importer's twin in the program root is a merge of the chain, with the root's own names first.TsLint. It stages the views, and each importer link the lint configuration's
datanames is laid over them as its tree (tsaction tsgo -runtime_link), where the program root holds that importer, so the configuration's imports run under Node from the trees. Putting TsLint on views matters for time, not only for files: a target's TsgoCheck and TsLint then stage the same input root, and the worker reuses it. With TsLint on the trees and TsgoCheck on views, both lost that reuse and the pair ran about 20% slower than with views off.Compatibility. A
TsInfobuilt withoutnpm_view_filesmakes its dependents' programs read the trees, soprevious_shape_providerstill analyzes. Analysis declares the views and twin links whatever the flag, which roughly doubles a lockfile's symlink artifacts.Escape hatches.
type_views = Falseon ats_compileorts_teststages the trees in that program's type actions only; its dependents keep their own choice, and no configuration changes, so the stores are analyzed once.--//ts:type_views=falsedoes it for every program, for comparisons and rollback. Analysis tests cover both.Benchmark. The lovable monorepo at
main(821ff4ed, which has//:oxlint_config_node_modulesints.lint'sdata) builds everyts_compileandts_test(1,058 programs) against this branch through--override_module. TsgoCheck, TsLint and TsgoDeclare are forced to execute (no-cache,--use_action_cache=false) on Buildbarn, in the order off, on, off. Times are worker spans from Buildbarn traces, summed over the actions, and the off column averages the two off runs.The execution rows move with cluster load (the two off runs differ by 12% there); the input files and input fetch are the change's own effect.
Verification.
mainemits hash identically in the three runs, and no type action fails with views on.bazel test --config=fast //...passes, apart from targets this NixOS machine cannot build (no/bin/bash, protoc, Cargo build scripts), which fail with views off too.TestTypeViewKeepsWhatResolutionReadspins the filter, links included, andTestBinRelativepins the twin importer paths.TestRuntimeLink…pin where a lint configuration's links land, the lint analysis tests that TsLint lays them over the views, and//tests/npm/trees:app_chain_testand//tests/npm:app_trees_flag_chain_testthat the attribute and the flag stage only trees. The analysis tests that pin the importer chain, the staged inputs and the ownership manifest now expect the views..mjs/.cjspairing, and the oldTsInfoshape.