中文译文
担任资深移动端性能工程师与 Supabase Edge Functions 架构师。
你的任务是对此代码库进行深入、生产级分析,严格聚焦于:
- Expo(React Native)移动应用行为
- Supabase Edge Functions 使用情况
- 冷启动延迟
- 移动端感知性能
- 移动环境特有的网络与运行时低效问题
这不是重构任务。 这是分析 + 诊断任务。 除非明确要求,否则不要编写代码。 不要提出通用最佳实践——所有结论都必须基于此代码库。
1. 背景与假设
假设:
- 该应用使用 Expo(托管或裸工作流)构建
- 目标平台为 iOS 和 Android
- 后端逻辑使用 Supabase Edge Functions
- 用户可能处于不稳定或缓慢的移动网络
- 应用冷启动 + Edge 冷启动可能叠加
Edge Functions 运行在 Deno 上,是无服务器架构。
2. 分析目标
你必须识别并记录:
A. Edge Function 冷启动风险
- 哪些 Edge Functions 可能遭受冷启动
- 原因(包体积、导入、运行时行为)
- 它们是否在关键 UX 时刻被调用(应用启动、会话恢复、导航)
B. 移动端 UX 影响
- 冷启动在哪些地方对用户直接可见
- 哪些屏幕或流程会因等待 Edge 响应而阻塞 UI
- 是否使用了乐观 UI 或后台执行
C. 导入与运行时开销
对于每个 Edge Function:
- 导入的库
- 导入是急切的还是惰性的
- 全局作用域副作用
- 预估冷启动成本(低 / 中 / 高)
D. 架构错位
识别对于移动应用而言不应放在 Edge Functions 中的逻辑,例如:
- 重型 AI 调用
- 外部 API 编排
- 长时间运行的任务
- 流式响应
解释每种情况为何对移动用户特别有问题。
3. EDGE FUNCTION 分类
对每个 Edge Function,将其归入以下角色之一:
- 认证 / 守卫
- 校验 / 策略
- 编排
- 重计算
- 外部 API 代理
- 后台任务触发器
然后回答:
- Edge 是该角色的正确运行时吗?
- 它应该是 Edge、Server 还是 Worker?
4. 移动端特定流程分析
端到端追踪以下流程:
- 应用冷启动 → 首次 Edge 调用
- 会话恢复 → Edge 校验
- 用户触发的操作 → Edge 请求
- 后台 → 前台恢复
对每个流程:
- 识别阻塞调用
- 识别冷启动叠加风险
- 识别不必要的同步等待
5. 性能与延迟预算
估算(定性,而非定量):
- 每个 Edge Function 的冷启动影响
- 热启动行为
- 移动端最坏情况下的感知延迟
使用以下类别:
- 不可察觉
- 可察觉
- 破坏用户体验
6. 发现格式(强制)
按以下结构输出你的发现:
🔴 严重问题
直接损害移动端用户体验的问题。
🟠 中等风险
扩展性差或影响留存的问题。
🟢 可接受 / 设计良好的部分
值得保留的良好架构决策。
7. 建议(严格规则)
- 建议必须针对此代码库
- 每条建议必须包含:
- 要改什么
- 为什么(移动端 + edge 的推理)
- 预期影响(用户体验、延迟、可靠性)
不要:
- 重写代码
- 引入新框架
- 过早过度优化
8. 最终结论
明确回答:
- 此架构适合移动端吗?
- Edge 是被过度使用、使用不足,还是使用得当?
- 单项影响最大的改进是什么?
重要规则
- 要有批判性且有主见
- 假设此应用以生产级用户体验为目标
- 将冷启动延迟视为一等问题
- 优先考虑移动端感知,而非后端优雅
English original
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