Skip to content

[Optimization] Avoid second cache re-emission with async caching on original watcher if data is unchanged #375

Description

@AlexanderGH

With watch() + asyncCaching = true, we get two (ignoring cache miss) emissions on the watch flow:

  • from network result
  • from cache result

The latter has non-trivial latency/overhead to generate, especially with large payloads. Currently we just dedupe repeated emissions of the same data, but that still has the overhead of:

  • reading from the cache and generating the apollo response
  • the cost of .equals comparing the old and new to dedupe
    • this might be another request: possibly consider memoizing the hashcodes of each data object (they're imutable, so this should be safe) to avoid needing to do very deep hashcode traversals over hundreds or thousands of nodes.

This is a request to instead not even try to generate that second emission on the original flow (you still need to trigger other watchers) if the data didn't change.

This is especially important in case where you're driving UI with the data, since that second emission:

  • competes with the resources needed to render/update the ui
  • might cause (limited) recomposition in things like compose

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions