microts: AOT inlines every child component instance into each ancestor and also emits an unreachable standalone view per component
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 12/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- rust, typescript
- Área
- compilers, performance
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.6k
- Forks
- 88
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pocket-stack/pocketjs
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
pocket-stack/pocketjs#756 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pocket-stack/pocketjs#746 ·
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
pocket-stack/pocketjs#745 ·
-
cli: the type check of pocket compile resolves "./app" to the view when the model is app.d.tsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
pocket-stack/pocketjs#743 ·
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
pocket-stack/pocketjs#744 ·
Todos los issues de pocket-stack/pocketjs
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día
-
security: set top-level least-privilege permissions in five workflowsPosiblemente ocupada @JonathanTSilva la tomó hoy. Abiertopriority: p2 size: xs type: security
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
JonathanTSilva/jts-website#150 ·
Los mantenedores suelen responder en 1 día
-
[BUG] SETUP.md is out of dateAbiertobug Needs Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
scottbenton/Iron-Link#437 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
speakeasy-api/speakeasy#2159 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
vercel-labs/ui#1066 ·
Los mantenedores suelen responder en 1 día