Skip to content
Source
Sign inSign up
TanStack/db

Seeing 40%+ slowness in simple useLiveQuery vs redux selectors when rendering many items #445

Send to my agent
Closedskidrowe(GitHub profile, opens in a new tab) opened this issue 3 comments

We have a React app that uses redux/re-reselect to render many items on the screen at a time. Switching the code to use tanstack db/useLiveQuery causes 40% or more speed reduction. A simple runnable example is attached...

return useLiveQuery(q =>
    q
      .from({ item: orderCollection })
      .where(({ item }) => eq(item.gridId, gridId))
      .where(({ item }) => eq(item.rowId, rowId))
      .where(({ item }) => eq(item.side, side))
  );

vs

useSelector((state:IStore) => getOrderBySideAndRowId(state, props));

test.zip

  1. Updated to latest and added dependency array.

    test2.zip

  2. @skidrowe you still see a 40% slowdown? Or has that changed?

  3. Ok I finally got this fixed — https://github.com/TanStack/db/pull/1987 I had Opus 5.5 churn away for a couple of days and this is where we're at now:

    mainThis PRRedux
    Mount 240 queries (median)8.2 ms2.2–2.3 ms2.1–2.2 ms
    Update a batch of 200 rows3.9 ms0.97–1.04 ms0.93–1.02 ms
    Mount, useLiveQuery({ query })14–16 ms2.5–2.7 ms2.1–2.2 ms
    Mount, the same query with orderBy13.0–14.6 ms2.6–3.4 ms2.3–3.0 ms

Sign in to join this conversation.