import {Stack,Typography} from "@mui/material";import type {Gallery_Capture_Session,Gallery_Performance_Capture} from "../protocol/gallery_types";import {Json_Viewer} from "../common/json_viewer";
export function Plan_Comparison({capture,session}:{capture:Gallery_Performance_Capture;session:Gallery_Capture_Session}) {if(session.plan_statistics.length<2)return <Typography color="text.secondary">捕获不同 Render Plan 版本后可比较拓扑与性能。</Typography>;const first=session.plan_statistics[0],second=session.plan_statistics.at(-1)!;const first_plan=capture.plans.find(plan=>plan.version===first.render_plan_version),second_plan=capture.plans.find(plan=>plan.version===second.render_plan_version);const first_nodes=new Set(first_plan?.nodes.map(node=>node.node_id)),second_nodes=new Set(second_plan?.nodes.map(node=>node.node_id));return <Stack><Typography>Plan v{first.render_plan_version} → v{second.render_plan_version}</Typography><Json_Viewer value={{render_average_ns:[first.render_average_ns,second.render_average_ns],render_p95_ns:[first.render_p95_ns,second.render_p95_ns],added_nodes:[...second_nodes].filter(id=>!first_nodes.has(id)),removed_nodes:[...first_nodes].filter(id=>!second_nodes.has(id))}}/></Stack>;}
