getNotificationType/main-timeline gate re-derives push rules on every event without memoization #77

Closed
opened 2026-09-12 01:51:29 -04:00 by jared · 0 comments
Owner

Severity: low · Type: performance · Confidence: medium

Location: src/app/utils/room.ts:191-209, src/app/pages/client/ClientNonUIFeatures.tsx:598-617

Problem

getNotificationType is called synchronously inside the RoomEvent.Timeline handler for every single live timeline event in every room (via mx.getRoomPushRule + a full linear scan of pushRules.global.override when no room-kind rule exists, findMutedRule). In a very active server/account with many muted rooms and a bursty sync (catch-up after reconnect), this results in an O(events × override-rules) rescan with no caching, all synchronously on the event-emission microtask. Not correctness-affecting, but a case of "heavy per-event work" the brief calls out explicitly.

How to trigger

Reconnect after being offline in an account with many rooms/override rules and receive a backlog of timeline events across many rooms at once.

Suggested fix

Memoize getNotificationType per (pushRulesEventId, roomId) (it already only changes when the m.push_rules account-data event updates), invalidating the cache when AccountDataEvent.PushRules changes instead of recomputing per event.


Filed from the September 2026 client audit (branch lotus @ 4bea4895).

**Severity:** low · **Type:** performance · **Confidence:** medium **Location:** `src/app/utils/room.ts:191-209`, `src/app/pages/client/ClientNonUIFeatures.tsx:598-617` ### Problem `getNotificationType` is called synchronously inside the `RoomEvent.Timeline` handler for every single live timeline event in every room (via `mx.getRoomPushRule` + a full linear scan of `pushRules.global.override` when no room-kind rule exists, `findMutedRule`). In a very active server/account with many muted rooms and a bursty sync (catch-up after reconnect), this results in an O(events × override-rules) rescan with no caching, all synchronously on the event-emission microtask. Not correctness-affecting, but a case of "heavy per-event work" the brief calls out explicitly. ### How to trigger Reconnect after being offline in an account with many rooms/override rules and receive a backlog of timeline events across many rooms at once. ### Suggested fix Memoize `getNotificationType` per `(pushRulesEventId, roomId)` (it already only changes when the `m.push_rules` account-data event updates), invalidating the cache when `AccountDataEvent.PushRules` changes instead of recomputing per event. --- _Filed from the September 2026 client audit (branch `lotus` @ 4bea4895)._
jared added this to the Audit 2026-09 · Medium & Low milestone 2026-09-12 01:51:29 -04:00
jared added the bugpriority: lowperformancearea: notifications labels 2026-09-12 01:51:29 -04:00
jared self-assigned this 2026-09-12 01:51:29 -04:00
jared closed this issue 2026-09-12 20:29:07 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/cinny#77