#Optimization help

4 messages · Page 1 of 1 (latest)

fluid lynx
#

do you see any opportunities for improvement here on the file provided? Its a provider that allows for sitewide context of the users carts and users subscription data. if not can we achieve the same logic with less? is this overkill or is this actually good practive according to convex?

thorn ospreyBOT
#

Hi @fluid lynx. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I apologize, but I don't have access to the file you're referring to. Without seeing the specific code or implementation details, I can't provide a detailed analysis or suggestions for optimization. However, I can offer some general best practices for working with Convex and context providers based on the information available in the knowledge sources.

  1. Query Caching: Convex provides built-in caching for queries. If you're using the same query multiple times on a page, the Convex React library automatically collapses them into a single subscription, which can help optimize performance Discord support thread (https://discord.com/channels/1019350475847499849/1283845082738593933).

  2. Client-side Caching: For data that doesn't change frequently (like profile photos, names, or document titles), you might want to consider using client-side caching to reduce the number of function calls. Convex offers helpers for query caching that can keep subscription caches alive during unmount/remount cycles Discord support thread (https://discord.com/channels/1019350475847499849/1283845082738593933).

  3. Session Management: If you're managing user sessions, Convex recommends using session IDs to associate data with users. This can be useful for anonymous users or for maintaining state across multiple tabs Session Tracking Via Parameter Injection (https://stack.convex.dev/track-sessions-without-cookies).

  4. Data Segmentation: To optimize for caching and reduce unnecessary function calls, consider segmenting your data. For example, separate tables for heartbeats, shopping carts, presence data, etc., can be more efficient than storing everything in a single session document Avoid sprawling session documents (https://stack.convex.dev/track-sessions-without-cookies#avoid-sprawling-session-documents).

#
  1. Use of Helpers: Convex recommends using helper functions to share business logic, authorization code, and more. This can help reduce code duplication and make your functions more efficient Best Practices (https://docs.convex.dev/production/best-practices/#functions).

Without seeing your specific implementation, it's hard to say if your approach is overkill or not. The best practice is to start simple and optimize as needed based on your specific use case and performance requirements. If you're concerned about the complexity or efficiency of your implementation, you might want to share your code (with sensitive information removed) in the Convex Discord community for more specific feedback.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: