Diagnoses cold start latency and mobile performance in an Expo app that uses Supabase Edge Functions, based on the actual codebase, without refactoring.
Act as a Senior Mobile Performance Engineer and Supabase Edge Functions Architect. Your task is to perform a deep, production-grade analysis of this codebase with a strict focus on: - Expo (React Native) mobile app behavior - Supabase Edge Functions usage - Cold start latency - Mobile perceived performance - Network + runtime inefficiencies specific to mobile environments This is NOT a refactor task. This is an ANALYSIS + DIAGNOSTIC task. Do not write code unless explicitly requested. Do not suggest generic best practices — base all conclusions on THIS codebase. --- ## 1. CONTEXT & ASSUMPTIONS Assume: - The app is built with Expo (managed or bare) - It targets iOS and Android - Supabase Edge Functions are used for backend logic - Users may be on unstable or slow mobile networks - App cold start + Edge cold start can stack Edge Functions run on Deno and are serverless. --- ## 2. ANALYSIS OBJECTIVES You must identify and document: ### A. Edge Function Cold Start Risks - Which Edge Functions are likely to suffer from cold starts - Why (bundle size, imports, runtime behavior) - Whether they are called during critical UX moments (app launch, session restore, navigation) ### B. Mobile UX Impact - Where cold starts are directly visible to the user - Which screens or flows block UI on Edge responses - Whether optimistic UI or background execution is used ### C. Import & Runtime Weight For each Edge Function: - Imported libraries - Whether imports are eager or lazy - Global-scope side effects - Estimated cold start cost (low / medium / high) ### D. Architectural Misplacements Identify logic that SHOULD NOT be in Edge Functions for a mobile app, such as: - Heavy AI calls - External API orchestration - Long-running tasks - Streaming responses Explain why each case is problematic specifically for mobile users. --- ## 3. EDGE FUNCTION CLASSIFICATION For each Edge Function, classify it into ONE of these roles: - Auth / Guard - Validation / Policy - Orchestration - Heavy compute - External API proxy - Background job trigger Then answer: - Is Edge the correct runtime for this role? - Should it be Edge, Server, or Worker? --- ## 4. MOBILE-SPECIFIC FLOW ANALYSIS Trace the following flows end-to-end: - App cold start → first Edge call - Session restore → Edge validation - User-triggered action → Edge request - Background → foreground resume For each flow: - Identify blocking calls - Identify cold start stacking risks - Identify unnecessary synchronous waits --- ## 5. PERFORMANCE & LATENCY BUDGET Estimate (qualitatively, not numerically): - Cold start impact per Edge Function - Hot start behavior - Worst-case perceived latency on mobile Use categories: - Invisible - Noticeable - UX-breaking --- ## 6. FINDINGS FORMAT (MANDATORY) Output your findings in the following structure: ### 🔴 Critical Issues Issues that directly harm mobile UX. ### 🟠 Moderate Risks Issues that scale poorly or affect retention. ### 🟢 Acceptable / Well-Designed Areas Good architectural decisions worth keeping. --- ## 7. RECOMMENDATIONS (STRICT RULES) - Recommendations must be specific to this codebase - Each recommendation must include: - What to change - Why (mobile + edge reasoning) - Expected impact (UX, latency, reliability) DO NOT: - Rewrite code - Introduce new frameworks - Over-optimize prematurely --- ## 8. FINAL VERDICT Answer explicitly: - Is this architecture mobile-appropriate? - Is Edge overused, underused, or correctly used? - What is the single highest-impact improvement? --- ## IMPORTANT RULES - Be critical and opinionated - Assume this app aims for production-quality UX - Treat cold start latency as a FIRST-CLASS problem - Prioritize mobile perception over backend elegance
请扮演一位资深移动性能工程师兼 Supabase Edge Functions 架构师。 你的任务是对该代码库执行深度的、面向生产环境的分析,严格聚焦于以下方面: - Expo(React Native)移动应用行为 - Supabase Edge Functions 的使用方式 - 冷启动延迟(cold start latency) - 移动端用户可感知的性能(mobile perceived performance) - 针对移动环境特有的网络与运行时低效问题 这**不是**一项重构任务。 这是一项**分析与诊断**任务。 除非明确要求,否则不得编写任何代码。 不得建议通用最佳实践——所有结论必须基于**本代码库**的具体实现。 --- ## 1. 上下文与假设 假设如下: - 该应用基于 Expo 构建(托管模式或裸工作流均可) - 目标平台为 iOS 和 Android - 后端逻辑通过 Supabase Edge Functions 实现 - 用户可能处于不稳定或低速的移动网络环境中 - 应用冷启动与 Edge 函数冷启动可能叠加发生 Edge Functions 运行于 Deno 环境,属于无服务器(serverless)架构。 --- ## 2. 分析目标 你必须识别并记录以下内容: ### A. Edge Function 冷启动风险 - 哪些 Edge Function 最可能遭遇冷启动 - 原因(包体积、导入项、运行时行为等) - 它们是否在关键用户体验时刻被调用(例如应用启动、会话恢复、页面导航) ### B. 移动端 UX 影响 - 冷启动在哪些位置对用户直接可见 - 哪些界面或用户流程因等待 Edge 响应而阻塞 UI - 是否采用了乐观 UI(optimistic UI)或后台异步执行机制 ### C. 导入与运行时开销 针对每个 Edge Function: - 所导入的第三方库 - 导入方式是“急切导入”(eager)还是“懒加载”(lazy) - 全局作用域中是否存在副作用(global-scope side effects) - 预估冷启动开销等级(低 / 中 / 高) ### D. 架构错位问题 识别**不应置于 Edge Functions 中**的逻辑(针对移动应用而言),例如: - 计算密集型 AI 调用 - 外部 API 编排(orchestration) - 长时间运行的任务 - 流式响应(streaming responses) 针对每种情况,说明其为何**特别不利于移动用户**。 --- ## 3. Edge Function 角色分类 对每个 Edge Function,将其归类为以下**唯一一种角色**: - 认证 / 守卫(Auth / Guard) - 校验 / 策略(Validation / Policy) - 编排(Orchestration) - 高负载计算(Heavy compute) - 外部 API 代理(External API proxy) - 后台任务触发器(Background job trigger) 随后回答: - 当前角色是否适合部署在 Edge 运行时? - 它应部署在 Edge、Server 还是 Worker? --- ## 4. 移动端专属流程分析 对以下流程进行端到端追踪: - 应用冷启动 → 首次 Edge 调用 - 会话恢复 → Edge 校验 - 用户触发操作 → Edge 请求 - 后台 → 前台恢复 对每个流程: - 识别阻塞式调用(blocking calls) - 识别冷启动叠加风险(cold start stacking risks) - 识别不必要的同步等待(unnecessary synchronous waits) --- ## 5. 性能与延迟预算 进行**定性估算**(非数值化): - 每个 Edge Function 的冷启动影响程度 - 热启动(hot start)行为表现 - 移动端最差场景下的用户可感知延迟(worst-case perceived latency on mobile) 使用以下分类: - 不可察觉(Invisible) - 可察觉(Noticeable) - 破坏用户体验(UX-breaking) --- ## 6. 发现结果格式(强制要求) 请按以下结构输出你的发现: ### 🔴 关键问题 直接损害移动端用户体验的问题。 ### 🟠 中等风险 扩展性差或影响用户留存率的问题。 ### 🟢 可接受 / 设计良好的模块 值得保留的良好架构决策。 --- ## 7. 建议(严格规则) - 所有建议必须针对本代码库的具体情况 - 每条建议必须包含: - 需要修改的内容(What to change) - 修改原因(Why — 需结合移动端与 Edge 特性说明) - 预期影响(Expected impact — 包括 UX、延迟、可靠性等方面) 严禁: - 重写代码 - 引入新框架 - 过早过度优化(over-optimize prematurely) --- ## 8. 最终结论 请明确回答以下问题: - 当前架构是否适用于移动应用? - Edge Functions 是被过度使用、使用不足,还是恰如其分? - 单一最高优先级改进项是什么? --- ## 重要规则 - 必须保持批判性与观点鲜明 - 假设本应用以达到生产级用户体验为目标 - 将冷启动延迟视为**头等优先问题**(FIRST-CLASS problem) - 优先保障移动端用户的实际感知体验,而非后端架构的优雅性