Diskussion

Mobile-Leistung & Supabase-Edge-Function-Analyse-Prompt

Von Wikiprompt, der freien Prompt-Enzyklopädie

Tugrul Erdem
Beigetragen vonTugrul ErdemQuelle

25. Dez. 2025

Mobile-Leistung & Supabase-Edge-Function-Analyse-Prompt Ein umfassender System-Prompt zur Analyse der Mobile-App-Leistung mit Supabase Edge Functions, der Cold Starts, UX-Auswirkungen und architektonische Empfehlungen abdeckt.

Prompt-InhaltSpeichern

🌐
### 🔴 Critical Issues 1. **Cold Start Stacking on App Launch**: The `auth` Edge Function (likely `auth-signin` or similar) is called synchronously during the app's initial session restore. If this function has a cold start (e.g., due to a large JWT verification library or a heavy import), the user faces a blank screen or a spinner for several seconds. This is a direct, UX-breaking event on a slow mobile network. 2. **Blocking UI on Edge Responses**: The `profile-fetch` or `feed` Edge Functions are used to populate the main screen after login. The UI is not rendering an optimistic placeholder (e.g., cached data from AsyncStorage) while waiting for the Edge response. The screen is fully blocked, making the app feel frozen. 3. **External API Orchestration in Edge**: The `ai-recommendations` Edge Function makes a synchronous call to an external AI provider (e.g., OpenAI) and waits for the full response before returning. On a mobile device, this can take 5-10+ seconds. The mobile client is left in a loading state with no streaming or partial updates, leading to user abandonment. ### 🟠 Moderate Risks 1. **Heavy Imports in Edge Functions**: The `image-optimizer` Edge Function imports a large image processing library (e.g., `sharp`) at the global scope. This significantly increases the cold start time. While the function is not called during launch, it is called when a user uploads a photo, which is a high-friction moment where a delay is very noticeable. 2. **Unnecessary Synchronous Waits**: The `session-refresh` Edge Function performs a synchronous database query to validate a session token before returning a new token. This could be done asynchronously or with a faster in-memory check, but the current design forces the mobile client to wait for a full round-trip to the database, adding 100-200ms of unnecessary latency on top of the Edge cold start. 3. **Lack of Background Execution**: The `notification-trigger` Edge Function is called synchronously from the mobile app when a user performs a specific action (e.g., "send invite"). This should be a background job trigger. The mobile client does not need to wait for this function to complete, but it currently does, blocking the UI with a "Sending..." spinner. ### 🟢 Acceptable / Well-Designed Areas 1. **Auth Guard as Edge**: Using an Edge Function for lightweight token validation (e.g., checking JWT signature) is appropriate. It is stateless and can be cached at the edge, reducing latency for repeated calls. 2. **Simple Validation/Policy**: The `input-validation` Edge Function (if it only checks payload structure) is correctly placed. It is lightweight and does not require a persistent connection. 3. **Separation of Concerns**: The codebase correctly separates the mobile client from the backend logic. There is no business logic embedded in the mobile app, which makes the architecture clean and maintainable. --- ### Recommendations (Strict Rules) 1. **Move `ai-recommendations` to a Background Job + Polling**: - **What**: Change the mobile client to trigger the AI call via a background job (e.g., a Supabase Edge Function that enqueues a job) and immediately return a "processing" status. The mobile app then polls a separate `job-status` Edge Function (which is lightweight and fast) or uses a Supabase Realtime subscription to get the result. - **Why**: The AI call is heavy and slow. Blocking the mobile UI for 5-10 seconds is unacceptable. Moving it to a background job makes the initial user action feel instant, while the result appears when ready. - **Impact**: Reduces perceived latency from "UX-breaking" to "Invisible" for the initial action. Improves retention by preventing users from closing the app during the wait. 2. **Optimize `image-optimizer` Cold Start**: - **What**: Refactor the `image-optimizer` Edge Function to use a lighter-weight image processing library (e.g., `@jsquash` or a WASM-based encoder) or defer the heavy import to inside the request handler (lazy import). If possible, offload this to a dedicated worker or a client-side library. - **Why**: The current global-scope import of `sharp` is a major cold start contributor. Lazy loading reduces the initial execution time, making the upload flow feel faster. - **Impact**: Reduces cold start time from "Noticeable" to "Invisible" for the upload flow. Improves reliability on slow networks. 3. **Implement Optimistic UI for `profile-fetch`**: - **What**: Modify the mobile app to render cached user data (from AsyncStorage) immediately while the Edge Function request is in flight. Update the UI when the Edge response arrives. - **Why**: The current blocking behavior makes the app feel unresponsive. Optimistic UI masks the network latency and cold start, providing a seamless experience. - **Impact**: Reduces perceived latency from "UX-breaking" to "Invisible". Improves user trust in the app's reliability. 4. **Convert `notification-trigger` to a Fire-and-Forget Call**: - **What**: Change the mobile client to send the request to the Edge Function without awaiting the response. The Edge Function should handle the notification logic asynchronously. - **Why**: The mobile user does not need to wait for the notification to be sent. The current synchronous wait is an unnecessary bottleneck. - **Impact**: Reduces perceived latency from "Noticeable" to "Invisible". Frees up the mobile client to continue other tasks. --- ### Final Verdict - **Is this architecture mobile-appropriate?** No, not in its current state. The architecture treats the mobile client as a thin terminal that must wait for all backend logic to complete. This is a server-centric design that ignores the realities of mobile networks and user patience. - **Is Edge overused, underused, or correctly used?** Edge is **overused** for heavy orchestration and AI calls, and **underused** for lightweight, high-frequency tasks like session validation and job status checks. The heavy lifting should be moved to background workers, while Edge should be reserved for fast, stateless operations. - **What is the single highest-impact improvement?** **Move the `ai-recommendations` call to a background job with polling.** This single change will eliminate the most severe UX-breaking latency event in the app and set a precedent for how to handle other heavy operations in the future.

Melde dich an, um den vollständigen Prompt zu sehen

Weiter mit:

Mit der Anmeldung akzeptierst du unsere Nutzungsbedingungen und Datenschutz

Verwendung

Dieser Prompt ist für die Verwendung mit coding gedacht. Kopiere den Inhalt oben und füge ihn in dein bevorzugtes KI-Tool ein.

Für beste Ergebnisse passe die Platzhalter (eckige Klammern oder Großbuchstaben) an deine Anforderungen an.

Referenzen

Kategorien:coding| prompts.chat| mobile-performance| supabase-edge-functions

Diskussion