Guides

Performance

Where Time does its work, and how to keep that work small.

Time does its work in two steps, and caches each one:

  1. Reading events. Root runs your records through the adapter into a snapshot. This happens again only when the records change.
  2. Projecting the view. Root calls the active view's project with the snapshot and the visible range. This happens again only when the snapshot, range, options, resources, environment, or today's date change.

Everything else is Solid's own updates: what reads an accessor runs again when its value changes. These habits keep both steps rare and cheap.

Replace records, don't mutate them

Root compares events item by item. A new array with the same record objects in the same order counts as unchanged, so you can filter or map inline, as in events={meetings().filter((meeting) => !meeting.cancelled)}.

When the array changes, Time reads every record through the adapter again, except those with an unchanged revision; if every record comes out the same, in the same order, it keeps its interval indexes. Update records immutably: replace the changed record with a new object. A record changed in place keeps its identity, so if nothing else in the array changed, the item-by-item comparison sees no change and the calendar doesn't update.

Add a revision to your adapter

When you refetch, your data layer usually creates new objects for every record, even unchanged ones. getRevision lets Time skip those. Return anything that changes whenever the record changes, such as an updatedAt timestamp or a version number:

const bookingAdapter = defineEventAdapter<Booking>()({
  getId: (booking) => booking.id,
  getTitle: (booking) => booking.summary,
  getInterval: (booking) => ({ kind: "timed", start: booking.startsAt, end: booking.endsAt }),
  getResourceIds: (booking) => booking.roomIds,
  getRevision: (booking) => booking.updatedAt,
});

Records with the same ID and revision as last time reuse their earlier result. The revision must change whenever anything the adapter reads changes; otherwise Time keeps showing the old title or time.

Do the heavy work in project

A view's project runs only when its inputs change, while its Renderer updates whenever a prop it reads changes. Put filtering, sorting, and layout in project, and keep the Renderer to drawing.

Inside project, ask the snapshot for the visible range instead of looping over every event:

project: ({ snapshot, instantRange }) => snapshot.queryTimed(instantRange),

Queries use an interval index, so they don't scan every event. Each snapshot also remembers the results of its last 128 distinct queries, so asking again for the same range returns the same array.

Keep functions in options stable

Root compares locale, weekRules, now and a controlled anchorDate, timeZone or view by value, and each view's options key by key, so an inline options object is fine. Its values are compared by identity, though: a new function or nested object, such as a time grid's annotations, is a new value.

Solid reads an expression such as viewOptions={{ days: { days: days(), label: (date) => … } }} again whenever a signal in it changes, and each read makes a new function, so the view projects again. Define a function that an option takes once, outside the JSX, and pass it by name.

The same goes for a clock object. Change handlers and onDiagnosticsChange can be inline: Root reads them when it needs them.

Subscribe to what you use

useCalendarState() and useCalendar() give you the whole state, so what reads them runs again whenever any state changes. For one value, use a selector:

view-name.tsx
import { Calendar } from "./calendar";

export function ViewName() {
  const view = Calendar.useCalendarSelector((state) => state.view);
  return <span>{view()}</span>;
}

The accessor changes only when the selected value does. If your selector builds a new object each time, pass isEqual so equal results don't count as changes:

position.ts
export function usePosition() {
  return Calendar.useCalendarSelector(
    (state) => ({ view: state.view, anchorDate: state.anchorDate }),
    { isEqual: (a, b) => a.view === b.view && a.anchorDate.equals(b.anchorDate) },
  );
}

On this page