add additional sliding sync diagnostics and dynamically set timeline limit to reduce state churn
This commit is contained in:
1 parent
1c788c1e81
commit
6a76914010
2 files changed
+104
-13
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Box, Text } from 'folds';
|
||||
import { Box, Button, Icon, Icons, Text } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import { getClientSyncDiagnostics } from '$client/initMatrix';
|
||||
@@ -113,6 +113,7 @@ const formatListCoverage = (knownCount: number, rangeEnd: number): string => {
|
||||
export function SyncDiagnostics() {
|
||||
const mx = useMatrixClient();
|
||||
const [, setTick] = useState(0);
|
||||
const [expandSliding, setExpandSliding] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const intervalId = window.setInterval(() => setTick((v) => v + 1), 1000);
|
||||
@@ -163,14 +164,43 @@ export function SyncDiagnostics() {
|
||||
))}
|
||||
|
||||
{diagnostics.sliding && (
|
||||
<>
|
||||
<Text size="T300">Sliding proxy: {diagnostics.sliding.proxyBaseUrl}</Text>
|
||||
{diagnostics.sliding.lists.map((list) => (
|
||||
<Text size="T300" key={list.key}>
|
||||
List `{list.key}` coverage: {formatListCoverage(list.knownCount, list.rangeEnd)}
|
||||
</Text>
|
||||
))}
|
||||
</>
|
||||
<Box direction="Column" gap="100">
|
||||
<Box justifyContent="SpaceBetween" alignItems="Center">
|
||||
<Text size="T300">Sliding Sync</Text>
|
||||
<Button
|
||||
size="300"
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
radii="300"
|
||||
before={<Icon src={expandSliding ? Icons.ChevronTop : Icons.ChevronBottom} />}
|
||||
onClick={() => setExpandSliding((v) => !v)}
|
||||
>
|
||||
<Text size="B300">{expandSliding ? 'Collapse' : 'Expand'}</Text>
|
||||
</Button>
|
||||
</Box>
|
||||
{expandSliding && (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="T300">Sliding proxy: {diagnostics.sliding.proxyBaseUrl}</Text>
|
||||
<Text size="T300">
|
||||
Timeline limit: {diagnostics.sliding.timelineLimit} (page size:{' '}
|
||||
{diagnostics.sliding.listPageSize})
|
||||
</Text>
|
||||
<Text size="T300">
|
||||
Adaptive timeline: {diagnostics.sliding.adaptiveTimeline ? 'yes' : 'no'}
|
||||
</Text>
|
||||
<Text size="T300">
|
||||
Device/network: saveData {diagnostics.sliding.device.saveData ? 'on' : 'off'} |
|
||||
effectiveType {diagnostics.sliding.device.effectiveType ?? 'unknown'} | memory{' '}
|
||||
{diagnostics.sliding.device.deviceMemoryGb ?? 'unknown'} GB
|
||||
</Text>
|
||||
{diagnostics.sliding.lists.map((list) => (
|
||||
<Text size="T300" key={list.key}>
|
||||
List `{list.key}` coverage: {formatListCoverage(list.knownCount, list.rangeEnd)}
|
||||
</Text>
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</SequenceCard>
|
||||
|
||||
@@ -18,6 +18,9 @@ const LIST_JOINED = 'joined';
|
||||
const LIST_INVITES = 'invites';
|
||||
const DEFAULT_LIST_PAGE_SIZE = 50;
|
||||
const DEFAULT_TIMELINE_LIMIT = 30;
|
||||
const TIMELINE_LIMIT_LOW = 10;
|
||||
const TIMELINE_LIMIT_MEDIUM = 15;
|
||||
const TIMELINE_LIMIT_HIGH = 30;
|
||||
const DEFAULT_POLL_TIMEOUT_MS = 30000;
|
||||
const DEFAULT_MAX_ROOMS = 5000;
|
||||
|
||||
@@ -38,8 +41,18 @@ export type SlidingSyncListDiagnostics = {
|
||||
rangeEnd: number;
|
||||
};
|
||||
|
||||
export type SlidingSyncDeviceDiagnostics = {
|
||||
saveData: boolean;
|
||||
effectiveType: string | null;
|
||||
deviceMemoryGb: number | null;
|
||||
};
|
||||
|
||||
export type SlidingSyncDiagnostics = {
|
||||
proxyBaseUrl: string;
|
||||
timelineLimit: number;
|
||||
listPageSize: number;
|
||||
adaptiveTimeline: boolean;
|
||||
device: SlidingSyncDeviceDiagnostics;
|
||||
lists: SlidingSyncListDiagnostics[];
|
||||
};
|
||||
|
||||
@@ -48,6 +61,44 @@ const clampPositive = (value: number | undefined, fallback: number): number => {
|
||||
return Math.round(value);
|
||||
};
|
||||
|
||||
const resolveAdaptiveTimelineLimit = (
|
||||
configuredLimit: number | undefined,
|
||||
pageSize: number
|
||||
): number => {
|
||||
if (typeof configuredLimit === 'number' && configuredLimit > 0) {
|
||||
return clampPositive(configuredLimit, DEFAULT_TIMELINE_LIMIT);
|
||||
}
|
||||
|
||||
const navigatorLike = typeof navigator !== 'undefined' ? navigator : undefined;
|
||||
const connection = (navigatorLike as any)?.connection;
|
||||
const saveData = connection?.saveData === true;
|
||||
const effectiveType = connection?.effectiveType as string | undefined;
|
||||
const deviceMemory = (navigatorLike as any)?.deviceMemory as number | undefined;
|
||||
|
||||
if (saveData || effectiveType === 'slow-2g' || effectiveType === '2g') {
|
||||
return Math.min(pageSize, TIMELINE_LIMIT_LOW);
|
||||
}
|
||||
|
||||
if (effectiveType === '3g' || (typeof deviceMemory === 'number' && deviceMemory <= 4)) {
|
||||
return Math.min(pageSize, TIMELINE_LIMIT_MEDIUM);
|
||||
}
|
||||
|
||||
return Math.min(pageSize, TIMELINE_LIMIT_HIGH);
|
||||
};
|
||||
|
||||
const getDeviceDiagnostics = (): SlidingSyncDeviceDiagnostics => {
|
||||
const navigatorLike = typeof navigator !== 'undefined' ? navigator : undefined;
|
||||
const connection = (navigatorLike as any)?.connection;
|
||||
const effectiveType = connection?.effectiveType;
|
||||
const deviceMemory = (navigatorLike as any)?.deviceMemory;
|
||||
|
||||
return {
|
||||
saveData: connection?.saveData === true,
|
||||
effectiveType: typeof effectiveType === 'string' ? effectiveType : null,
|
||||
deviceMemoryGb: typeof deviceMemory === 'number' ? deviceMemory : null,
|
||||
};
|
||||
};
|
||||
|
||||
const buildDefaultSubscription = (timelineLimit: number): MSC3575RoomSubscription => ({
|
||||
timeline_limit: timelineLimit,
|
||||
required_state: [
|
||||
@@ -55,13 +106,10 @@ const buildDefaultSubscription = (timelineLimit: number): MSC3575RoomSubscriptio
|
||||
[EventType.RoomMember, MSC3575_STATE_KEY_LAZY],
|
||||
[EventType.RoomCreate, ''],
|
||||
[EventType.RoomName, ''],
|
||||
[EventType.RoomTopic, ''],
|
||||
[EventType.RoomAvatar, ''],
|
||||
[EventType.RoomCanonicalAlias, ''],
|
||||
[EventType.RoomPowerLevels, ''],
|
||||
[EventType.RoomEncryption, ''],
|
||||
[EventType.RoomTombstone, ''],
|
||||
[EventType.RoomPinnedEvents, ''],
|
||||
[EventType.RoomJoinRules, ''],
|
||||
[EventType.RoomHistoryVisibility, ''],
|
||||
[StateEvent.PoniesRoomEmotes, '*'],
|
||||
@@ -115,6 +163,10 @@ export class SlidingSyncManager {
|
||||
private readonly maxRooms: number;
|
||||
|
||||
private readonly listKeys: string[];
|
||||
private readonly timelineLimit: number;
|
||||
private readonly listPageSize: number;
|
||||
private readonly adaptiveTimeline: boolean;
|
||||
private readonly deviceDiagnostics: SlidingSyncDeviceDiagnostics;
|
||||
|
||||
private readonly onLifecycle: (state: SlidingSyncState, resp: unknown, err?: Error) => void;
|
||||
|
||||
@@ -128,10 +180,15 @@ export class SlidingSyncManager {
|
||||
config: SlidingSyncConfig
|
||||
) {
|
||||
const listPageSize = clampPositive(config.listPageSize, DEFAULT_LIST_PAGE_SIZE);
|
||||
const timelineLimit = clampPositive(config.timelineLimit, DEFAULT_TIMELINE_LIMIT);
|
||||
const adaptiveTimeline = !(typeof config.timelineLimit === 'number' && config.timelineLimit > 0);
|
||||
const timelineLimit = resolveAdaptiveTimelineLimit(config.timelineLimit, listPageSize);
|
||||
const pollTimeoutMs = clampPositive(config.pollTimeoutMs, DEFAULT_POLL_TIMEOUT_MS);
|
||||
this.probeTimeoutMs = clampPositive(config.probeTimeoutMs, 5000);
|
||||
this.maxRooms = clampPositive(config.maxRooms, DEFAULT_MAX_ROOMS);
|
||||
this.timelineLimit = timelineLimit;
|
||||
this.listPageSize = listPageSize;
|
||||
this.adaptiveTimeline = adaptiveTimeline;
|
||||
this.deviceDiagnostics = getDeviceDiagnostics();
|
||||
const includeInviteList = config.includeInviteList !== false;
|
||||
|
||||
const subscription = buildDefaultSubscription(timelineLimit);
|
||||
@@ -163,6 +220,10 @@ export class SlidingSyncManager {
|
||||
public getDiagnostics(): SlidingSyncDiagnostics {
|
||||
return {
|
||||
proxyBaseUrl: this.proxyBaseUrl,
|
||||
timelineLimit: this.timelineLimit,
|
||||
listPageSize: this.listPageSize,
|
||||
adaptiveTimeline: this.adaptiveTimeline,
|
||||
device: this.deviceDiagnostics,
|
||||
lists: this.listKeys.map((key) => {
|
||||
const listData = this.slidingSync.getListData(key);
|
||||
const params = this.slidingSync.getListParams(key);
|
||||
|
||||
Reference in new issue
Block a user