microts: AOT inlines every child component instance into each ancestor and also emits an unreachable standalone view per component
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 12/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust, typescript
- 领域
- compilers, performance
调研方向
Start in microts/compiler/aot-codegen.ts: read Codegen.expand (lines 354–366) to see why non-factory children are expanded into each parent, then the emission loop at line 1113 that walks program.components. Reproduce with the pocket.ts compile --aot command and grep -c '"zero"' gen/app.rs to confirm the 7 copies, and inspect how factory components stay as mounted child views. Done means unreachable standalone views are no longer emitted and per-component types are shared across instances, dropping the grep count and generated size.
由索引模型根据 Issue 内容生成。
描述
Version
PocketJS main (557ad61e). macOS 27.2 arm64, Bun 1.4.2.
Repro
pocket.host.json, pocket.host.config.ts (aot: true, model: "compiled") and main.tsx as in #720.
// app.ts
import { createSignal } from "solid-js";
import type { i32 } from "@pocketjs/framework/solid/std";
export const [count, setCount] = createSignal<i32>(0);
// Leaf.tsx
import { Show } from "solid-js";
import { Text, View } from "@pocketjs/framework/solid/components";
import type { i32 } from "@pocketjs/framework/solid/std";
export default function Leaf(props: { value: i32 }) {
return (
<View class="w-[60] h-[20]">
<Show when={props.value === 0}><Text class="text-xs text-slate-900">zero</Text></Show>
<Show when={props.value === 1}><Text class="text-xs text-slate-900">one</Text></Show>
<Show when={props.value === 2}><Text class="text-xs text-slate-900">two</Text></Show>
</View>
);
}
// Middle.tsx
import { View } from "@pocketjs/framework/solid/components";
import type { i32 } from "@pocketjs/framework/solid/std";
import Leaf from "./Leaf.tsx";
export default function Middle(props: { value: i32 }) {
return (
<View class="flex-col">
<Leaf value={props.value} />
<Leaf value={props.value + 1} />
</View>
);
}
// app.tsx
import { View } from "@pocketjs/framework/solid/components";
import { count, setCount } from "./app";
import Middle from "./Middle.tsx";
export default function App() {
return (
<View class="w-full h-full p-4 bg-slate-100" focusable onPress={() => setCount(count() + 1)}>
<Middle value={count()} />
<Middle value={count() + 2} />
</View>
);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
grep -c '"zero"' gen/app.rs
Actual
gen/app.rs holds the Leaf subtree 7 times: "zero" occurs 7 times. One copy is the standalone LeafView, two are inlined into the standalone MiddleView, and four are inlined into AppView.
| Prefix | Structs |
|---|---|
App (AppBlock, AppNode, …) |
54 |
Middle |
27 |
Leaf |
13 |
AppView's code refers to no Leaf* or Middle* type. The standalone LeafView and MiddleView, with their blocks and nodes, are not reachable from the root, but rustc still parses, type-checks and compiles them.
The size grows with the product of the instance counts along each path, plus one standalone copy per ancestor. In an application whose views are about 4,000 lines of TSX, where a 12-branch glyph component is used in ten colours inside a watch-face component inside the root, app.rs is 100 MB (2.8 million lines, 55,577 impl items):
| Generated prefix | Lines |
|---|---|
| root component | 1,155,193 |
| watch-face component (standalone, unreachable) | 581,466 |
| glyph component (standalone, unreachable) | 322,090 |
| others | 757,853 |
rustc (opt-level = "s", Xtensa target) takes 2 minutes and 5.1 GB of RSS for that crate on a 14-core host. On a 2-core, 7 GB CI runner it ran for 9.5 minutes and was killed by the OOM killer (SIGKILL).
Expected
pocket compile --aotemits the views reachable from the root component: without a component that is only ever inlined, its standalone view is dead code.- Instances of one component share their generated types (one block/node set per component, mounted per instance), so the generated size is the sum of the component sizes instead of the product of the instance counts along each path.
Cause
Codegen.expand (microts/compiler/aot-codegen.ts:354–366) expands the node tree of every non-factory child component into its parent (this.expand(component.nodes, …)); a factory component is kept as a child view. The emission loop (aot-codegen.ts:1113) generates a view for every component in program.components, whether or not anything mounts it.
Workaround
None in the view source: giving a component a model factory makes it a mounted child view, but changes its model ownership. Splitting the views does not help, because every instance is still expanded.
- 主要语言
- TypeScript
- 星标
- 1.6k
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pocket-stack/pocketjs 的其他 Issue
-
microts: a model local that every branch assigns raises unused_assignments in the generated Rust未关闭bug
难度 2/5 1-3 小时 新手友好度 80/100
pocket-stack/pocketjs#756 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
pocket-stack/pocketjs#746 ·
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
pocket-stack/pocketjs#745 ·
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
pocket-stack/pocketjs#743 ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
pocket-stack/pocketjs#744 ·
查看 pocket-stack/pocketjs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
security: set top-level least-privilege permissions in five workflows可能已有人在做 @JonathanTSilva 今天认领。 未关闭priority: p2 size: xs type: security
难度 2/5 1-3 小时 新手友好度 64/100
JonathanTSilva/jts-website#150 ·
维护者通常 1 天内回复
-
bug Needs Triage
难度 2/5 1-3 小时 新手友好度 82/100
scottbenton/Iron-Link#437 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
speakeasy-api/speakeasy#2159 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
vercel-labs/ui#1066 ·
维护者通常 1 天内回复