From 61e7eb8ff1d7ef222e60b687090cca53a182efc3 Mon Sep 17 00:00:00 2001 From: riku6460 <17585784+riku6460@users.noreply.github.com> Date: Tue, 4 Jul 2023 07:49:13 +0900 Subject: [PATCH 1/7] =?UTF-8?q?perf(backend):=20JSON.parse=20=E3=81=AE?= =?UTF-8?q?=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97=E3=82=92=E5=89=8A=E6=B8=9B?= =?UTF-8?q?=E3=81=99=E3=82=8B=20(#11091)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf(backend): JSON.parse の呼び出しを削減する Co-authored-by: Hidekazu Kobayashi * Update CHANGELOG.md --------- Co-authored-by: Hidekazu Kobayashi --- CHANGELOG.md | 3 +++ .../src/server/api/StreamingApiServerService.ts | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7f900509..c8fd80063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,9 @@ - Fix: サーバーメトリクスが90度傾いている - Fix: sparkle内にリンクを入れるとクリック不能になる問題の修正 +### Server +- JSON.parse の回数を削減することで、ストリーミングのパフォーマンスを向上しました + ## 13.13.2 ### General diff --git a/packages/backend/src/server/api/StreamingApiServerService.ts b/packages/backend/src/server/api/StreamingApiServerService.ts index 4a0342d2b..e4291becf 100644 --- a/packages/backend/src/server/api/StreamingApiServerService.ts +++ b/packages/backend/src/server/api/StreamingApiServerService.ts @@ -103,6 +103,13 @@ export class StreamingApiServerService { }); }); + const globalEv = new EventEmitter(); + + this.redisForSub.on('message', (_: string, data: string) => { + const parsed = JSON.parse(data); + globalEv.emit('message', parsed); + }); + this.#wss.on('connection', async (connection: WebSocket.WebSocket, request: http.IncomingMessage, ctx: { stream: MainStreamConnection, user: LocalUser | null; @@ -112,12 +119,11 @@ export class StreamingApiServerService { const ev = new EventEmitter(); - async function onRedisMessage(_: string, data: string): Promise { - const parsed = JSON.parse(data); - ev.emit(parsed.channel, parsed.message); + function onRedisMessage(data: any): void { + ev.emit(data.channel, data.message); } - this.redisForSub.on('message', onRedisMessage); + globalEv.on('message', onRedisMessage); await stream.listen(ev, connection); @@ -137,7 +143,7 @@ export class StreamingApiServerService { connection.once('close', () => { ev.removeAllListeners(); stream.dispose(); - this.redisForSub.off('message', onRedisMessage); + globalEv.off('message', onRedisMessage); this.#connections.delete(connection); if (userUpdateIntervalId) clearInterval(userUpdateIntervalId); }); From aa92df4e50f49537060bf0ff2199de839edcb5ca Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 4 Jul 2023 11:21:44 +0000 Subject: [PATCH 2/7] chore(frontend): add comment --- packages/frontend/src/scripts/clone.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/frontend/src/scripts/clone.ts b/packages/frontend/src/scripts/clone.ts index 16fad2412..cf8fa64ba 100644 --- a/packages/frontend/src/scripts/clone.ts +++ b/packages/frontend/src/scripts/clone.ts @@ -1,5 +1,7 @@ // structredCloneが遅いため // SEE: http://var.blog.jp/archives/86038606.html +// あと、Vue RefをIndexedDBに保存しようとしてstructredCloneを使ったらエラーになった +// https://github.com/misskey-dev/misskey/pull/8098#issuecomment-1114144045 type Cloneable = string | number | boolean | null | { [key: string]: Cloneable } | Cloneable[]; From 526fa8bf3f050bc928054d2a9dc8963a7507f874 Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 4 Jul 2023 22:48:39 +0900 Subject: [PATCH 3/7] perf(frontend): use setInterval instead of setTimeout chain in MkTime (#10981) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf(frontend): use setInterval instead of setTimeout chain in MkTime * fix * props.origin * props.origin 2 * fix * add comment * setIntervalを再設定する * refactor --- .../frontend/src/components/global/MkTime.vue | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/components/global/MkTime.vue b/packages/frontend/src/components/global/MkTime.vue index dfc3c8979..9b02f989b 100644 --- a/packages/frontend/src/components/global/MkTime.vue +++ b/packages/frontend/src/components/global/MkTime.vue @@ -9,7 +9,7 @@ From 92d9946f597c2b06552b23ba370708aea86575c0 Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 5 Jul 2023 00:59:37 +0900 Subject: [PATCH 4/7] enhance(frontend): Better Timeline(MkPagination) Experience (#11066) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance(frontend): Better MkPagination Appearance * fix * fix * 新規投稿が空でも先頭に戻ったらunshiftItemsする * use Map * refactor, 型エラー潰し * refactor --- .../frontend/src/components/MkPagination.vue | 170 +++++++++++++----- packages/frontend/src/pages/admin/abuses.vue | 2 +- .../src/pages/custom-emojis-manager.vue | 2 +- 3 files changed, 127 insertions(+), 47 deletions(-) diff --git a/packages/frontend/src/components/MkPagination.vue b/packages/frontend/src/components/MkPagination.vue index 598529bf5..b361d568e 100644 --- a/packages/frontend/src/components/MkPagination.vue +++ b/packages/frontend/src/components/MkPagination.vue @@ -21,14 +21,14 @@
- + {{ i18n.ts.loadMore }}
- +
- + {{ i18n.ts.loadMore }} @@ -50,6 +50,7 @@ import { i18n } from '@/i18n'; const SECOND_FETCH_LIMIT = 30; const TOLERANCE = 16; +const APPEAR_MINIMUM_INTERVAL = 600; export type Paging = { endpoint: E; @@ -71,6 +72,16 @@ export type Paging pageEl?: HTMLElement; }; + +type MisskeyEntityMap = Map; + +function arrayToEntries(entities: MisskeyEntity[]): [string, MisskeyEntity][] { + return entities.map(en => [en.id, en]); +} + +function concatMapWithArray(map: MisskeyEntityMap, entities: MisskeyEntity[]): MisskeyEntityMap { + return new Map([...map, ...arrayToEntries(entities)]); +}