perf: reuse the SDK singleton PushProcessor instead of allocating per call

new PushProcessor(room.client) was allocated per room on every sync cycle
(in the getUnreadInfo fallback path) and per component mount in
RoomTimeline/ThreadDrawer/notifications. The SDK already exposes a cached
singleton at mx.pushProcessor (client.ts:1293). Element Web uses the same
pattern. Replace all five allocations and drop the now-unused imports.
This commit is contained in:
Erwan Leboucher committed 2026-07-23 18:15:42 +02:00
1 parent 9f44c4c3ff
commit 8025a859f4
5 files changed
+6 -10

No files matched your search

+2 -2
View File
@@ -12,7 +12,7 @@ import {
import type { Editor } from 'slate';
import { useAtomValue, useSetAtom, useStore } from 'jotai';
import type { Room } from '$types/matrix-sdk';
import { PushProcessor, Direction, EventType } from '$types/matrix-sdk';
import { Direction, EventType } from '$types/matrix-sdk';
import classNames from 'classnames';
import type { VListHandle } from 'virtua';
import { VList } from 'virtua';
@@ -428,7 +428,7 @@ export function RoomTimeline({
const optionalSpace = useSpaceOptionally();
const roomParents = useAtomValue(roomToParentsAtom);
const imagePackRooms = useImagePackRooms(room.roomId, roomParents);
const pushProcessor = useMemo(() => new PushProcessor(mx), [mx]);
const pushProcessor = mx.pushProcessor;
const parseMemberEvent = useMemberEventParser();
const replyDraftAtom = useMemo(() => roomIdToReplyDraftAtomFamily(room.roomId), [room.roomId]);
+1 -2
View File
@@ -7,7 +7,6 @@ import {
Direction,
MatrixEvent,
MatrixEventEvent,
PushProcessor,
ReceiptType,
RelationType,
RoomEvent,
@@ -137,7 +136,7 @@ export function ThreadDrawer({ room, threadRootId, onClose, overlay }: ThreadDra
(userId: string) => jotaiStore.get(profilesCacheAtom)[userId],
[jotaiStore]
);
const pushProcessor = useMemo(() => new PushProcessor(mx), [mx]);
const pushProcessor = mx.pushProcessor;
const useAuthentication = useMediaAuthentication();
const mentionClickHandler = useMentionClickHandler(room.roomId);
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
@@ -7,7 +7,6 @@ import {
MatrixEventEvent,
RoomEvent,
SyncState,
PushProcessor,
EventType,
} from '$types/matrix-sdk';
@@ -327,7 +326,7 @@ export function BackgroundNotifications() {
});
}
const pushProcessor = new PushProcessor(mx);
const pushProcessor = mx.pushProcessor;
const handleAccountData = (event: MatrixEvent) => {
if (event.getType() === (EventType.Direct as string)) {
+1 -2
View File
@@ -11,7 +11,6 @@ import { getPresenceSyncManager } from '$client/initMatrix';
import {
MatrixEvent,
MatrixEventEvent,
PushProcessor,
RoomEvent,
SetPresence,
SyncState,
@@ -339,7 +338,7 @@ function MessageNotifications() {
}, []);
useEffect(() => {
const pushProcessor = new PushProcessor(mx);
const pushProcessor = mx.pushProcessor;
// Track encrypted events that should skip focus check when decrypted (because we
// already checked focus when the encrypted event arrived, and want to use that
// original state rather than re-checking after decryption completes).
+1 -2
View File
@@ -16,7 +16,6 @@ import {
EventTimeline,
EventType,
NotificationCountType,
PushProcessor,
PushRuleActionName,
RelationType,
MsgType,
@@ -427,7 +426,7 @@ export const getUnreadInfo = (room: Room, options?: UnreadInfoOptions): UnreadIn
const liveEvents = room.getLiveTimeline().getEvents();
let fallbackTotal = 0;
let fallbackHighlight = 0;
const pushProcessor = new PushProcessor(room.client);
const pushProcessor = room.client.pushProcessor;
for (let i = liveEvents.length - 1; i >= 0; i -= 1) {
const event = liveEvents[i];
if (!event) break;