Skip to content

Commit be50f2b

Browse files
committed
Adds optional binary serialization to ipc messages
- Improves performance on sending lots of data to the Graph
1 parent c9a9929 commit be50f2b

File tree

15 files changed

+106
-84
lines changed

15 files changed

+106
-84
lines changed

src/plus/webviews/graph/protocol.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export const UpdateSelectionCommandType = new IpcCommandType<UpdateSelectionPara
309309
export interface DidChangeParams {
310310
state: State;
311311
}
312-
export const DidChangeNotificationType = new IpcNotificationType<DidChangeParams>('graph/didChange', true);
312+
export const DidChangeNotificationType = new IpcNotificationType<DidChangeParams>('graph/didChange', true, true);
313313

314314
export interface DidChangeGraphConfigurationParams {
315315
config: GraphComponentConfig;
@@ -387,7 +387,11 @@ export interface DidChangeRowsParams {
387387
rowsStatsLoading: boolean;
388388
selectedRows?: GraphSelectedRows;
389389
}
390-
export const DidChangeRowsNotificationType = new IpcNotificationType<DidChangeRowsParams>('graph/rows/didChange');
390+
export const DidChangeRowsNotificationType = new IpcNotificationType<DidChangeRowsParams>(
391+
'graph/rows/didChange',
392+
undefined,
393+
true,
394+
);
391395

392396
export interface DidChangeRowsStatsParams {
393397
rowsStats: Record<string, GraphRowStats>;

src/system/logger.scope.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export function getLogScope(): LogScope | undefined {
1818
return scopes.get(scopeCounter);
1919
}
2020

21-
export function getNewLogScope(prefix: string): LogScope {
21+
export function getNewLogScope(prefix: string, scope?: LogScope | undefined): LogScope {
22+
if (scope != null) return { scopeId: scope.scopeId, prefix: `${scope.prefix}${prefix}` };
23+
2224
const scopeId = getNextLogScopeId();
2325
return {
2426
scopeId: scopeId,

src/webviews/apps/commitDetails/commitDetails.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ export class CommitDetailsApp extends App<Serialized<State>> {
105105
return disposables;
106106
}
107107

108-
protected override onMessageReceived(e: MessageEvent) {
109-
const msg = e.data as IpcMessage;
110-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
111-
108+
protected override onMessageReceived(msg: IpcMessage) {
112109
switch (msg.method) {
113110
// case DidChangeRichStateNotificationType.method:
114111
// onIpc(DidChangeRichStateNotificationType, msg, params => {
@@ -152,7 +149,7 @@ export class CommitDetailsApp extends App<Serialized<State>> {
152149
break;
153150

154151
default:
155-
super.onMessageReceived?.(e);
152+
super.onMessageReceived?.(msg);
156153
}
157154
}
158155

src/webviews/apps/home/home.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ export class HomeApp extends App<State> {
3838
return disposables;
3939
}
4040

41-
protected override onMessageReceived(e: MessageEvent) {
42-
const msg = e.data as IpcMessage;
43-
41+
protected override onMessageReceived(msg: IpcMessage) {
4442
switch (msg.method) {
4543
case DidChangeRepositoriesType.method:
46-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
47-
4844
onIpc(DidChangeRepositoriesType, msg, params => {
4945
this.state.repositories = params;
5046
this.state.timestamp = Date.now();
@@ -53,7 +49,7 @@ export class HomeApp extends App<State> {
5349
});
5450
break;
5551
default:
56-
super.onMessageReceived?.(e);
52+
super.onMessageReceived?.(msg);
5753
break;
5854
}
5955
}

src/webviews/apps/plus/account/account.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ export class AccountApp extends App<State> {
3131
return disposables;
3232
}
3333

34-
protected override onMessageReceived(e: MessageEvent) {
35-
const msg = e.data as IpcMessage;
36-
34+
protected override onMessageReceived(msg: IpcMessage) {
3735
switch (msg.method) {
3836
case DidChangeSubscriptionNotificationType.method:
39-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
40-
4137
onIpc(DidChangeSubscriptionNotificationType, msg, params => {
4238
this.state.subscription = params.subscription;
4339
this.state.avatar = params.avatar;
@@ -48,7 +44,7 @@ export class AccountApp extends App<State> {
4844
break;
4945

5046
default:
51-
super.onMessageReceived?.(e);
47+
super.onMessageReceived?.(msg);
5248
break;
5349
}
5450
}

src/webviews/apps/plus/focus/focus.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ export class FocusApp extends App<State> {
118118
}
119119
}
120120

121-
protected override onMessageReceived(e: MessageEvent) {
122-
const msg = e.data as IpcMessage;
123-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
124-
121+
protected override onMessageReceived(msg: IpcMessage) {
125122
switch (msg.method) {
126123
case DidChangeNotificationType.method:
127124
onIpc(DidChangeNotificationType, msg, params => {
@@ -130,6 +127,8 @@ export class FocusApp extends App<State> {
130127
this.attachState();
131128
});
132129
break;
130+
default:
131+
super.onMessageReceived?.(msg);
133132
}
134133
}
135134
}

src/webviews/apps/plus/graph/graph.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ import {
5151
UpdateSelectionCommandType,
5252
} from '../../../../plus/webviews/graph/protocol';
5353
import { Color, darken, getCssVariable, lighten, mix, opacity } from '../../../../system/color';
54+
import { debug } from '../../../../system/decorators/log';
5455
import { debounce } from '../../../../system/function';
56+
import { getLogScope, setLogScopeExit } from '../../../../system/logger.scope';
5557
import type { IpcMessage, IpcNotificationType } from '../../../protocol';
5658
import { onIpc } from '../../../protocol';
5759
import { App } from '../../shared/appBase';
@@ -73,7 +75,7 @@ const graphLaneThemeColors = new Map([
7375
]);
7476

7577
export class GraphApp extends App<State> {
76-
private callback?: UpdateStateCallback;
78+
private updateStateCallback?: UpdateStateCallback;
7779

7880
constructor() {
7981
super('GraphApp');
@@ -93,7 +95,7 @@ export class GraphApp extends App<State> {
9395
<GraphWrapper
9496
nonce={this.state.nonce}
9597
state={this.state}
96-
subscriber={(callback: UpdateStateCallback) => this.registerEvents(callback)}
98+
subscriber={(updateState: UpdateStateCallback) => this.registerUpdateStateCallback(updateState)}
9799
onColumnsChange={debounce<GraphApp['onColumnsChanged']>(
98100
settings => this.onColumnsChanged(settings),
99101
250,
@@ -139,14 +141,13 @@ export class GraphApp extends App<State> {
139141
// }
140142
// }
141143

142-
protected override onMessageReceived(e: MessageEvent) {
143-
const msg = e.data as IpcMessage;
144-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
144+
protected override onMessageReceived(msg: IpcMessage) {
145+
const scope = getLogScope();
145146

146147
switch (msg.method) {
147148
case DidChangeNotificationType.method:
148149
onIpc(DidChangeNotificationType, msg, (params, type) => {
149-
this.setState({ ...this.state, ...params.state }, type);
150+
this.setState({ ...this.state, ...params }, type);
150151
});
151152
break;
152153

@@ -215,26 +216,23 @@ export class GraphApp extends App<State> {
215216
const newRowsLength = params.rows.length;
216217

217218
this.log(
218-
`onMessageReceived(${msg.id}:${msg.method}): paging in ${newRowsLength} rows into existing ${previousRowsLength} rows at ${params.paging.startingCursor} (last existing row: ${lastId})`,
219+
scope,
220+
`paging in ${newRowsLength} rows into existing ${previousRowsLength} rows at ${params.paging.startingCursor} (last existing row: ${lastId})`,
219221
);
220222

221223
rows = [];
222224
// Preallocate the array to avoid reallocations
223225
rows.length = previousRowsLength + newRowsLength;
224226

225227
if (params.paging.startingCursor !== lastId) {
226-
this.log(
227-
`onMessageReceived(${msg.id}:${msg.method}): searching for ${params.paging.startingCursor} in existing rows`,
228-
);
228+
this.log(scope, `searching for ${params.paging.startingCursor} in existing rows`);
229229

230230
let i = 0;
231231
let row;
232232
for (row of previousRows) {
233233
rows[i++] = row;
234234
if (row.sha === params.paging.startingCursor) {
235-
this.log(
236-
`onMessageReceived(${msg.id}:${msg.method}): found ${params.paging.startingCursor} in existing rows`,
237-
);
235+
this.log(scope, `found ${params.paging.startingCursor} in existing rows`);
238236

239237
previousRowsLength = i;
240238

@@ -256,7 +254,7 @@ export class GraphApp extends App<State> {
256254
rows[previousRowsLength + i] = params.rows[i];
257255
}
258256
} else {
259-
this.log(`onMessageReceived(${msg.id}:${msg.method}): setting to ${params.rows.length} rows`);
257+
this.log(scope, `setting to ${params.rows.length} rows`);
260258

261259
if (params.rows.length === 0) {
262260
rows = this.state.rows;
@@ -281,6 +279,8 @@ export class GraphApp extends App<State> {
281279
}
282280
this.state.loading = false;
283281
this.setState(this.state, type);
282+
283+
setLogScopeExit(scope, ` \u2022 rows=${this.state.rows?.length ?? 0}`);
284284
});
285285
break;
286286

@@ -339,7 +339,7 @@ export class GraphApp extends App<State> {
339339
break;
340340

341341
default:
342-
super.onMessageReceived?.(e);
342+
super.onMessageReceived?.(msg);
343343
}
344344
}
345345

@@ -474,14 +474,14 @@ export class GraphApp extends App<State> {
474474
this.setState(this.state, 'didChangeTheme');
475475
}
476476

477+
@debug({ args: false, singleLine: true })
477478
protected override setState(state: State, type?: IpcNotificationType<any> | InternalNotificationType) {
478-
this.log(`setState()`);
479479
const themingChanged = this.ensureTheming(state);
480480

481481
this.state = state;
482482
super.setState({ timestamp: state.timestamp, selectedRepository: state.selectedRepository });
483483

484-
this.callback?.(this.state, type, themingChanged);
484+
this.updateStateCallback?.(this.state, type, themingChanged);
485485
}
486486

487487
private ensureTheming(state: State): boolean {
@@ -691,11 +691,11 @@ export class GraphApp extends App<State> {
691691
});
692692
}
693693

694-
private registerEvents(callback: UpdateStateCallback): () => void {
695-
this.callback = callback;
694+
private registerUpdateStateCallback(updateState: UpdateStateCallback): () => void {
695+
this.updateStateCallback = updateState;
696696

697697
return () => {
698-
this.callback = undefined;
698+
this.updateStateCallback = undefined;
699699
};
700700
}
701701
}

src/webviews/apps/plus/patchDetails/patchDetails.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ export class PatchDetailsApp extends App<Serialized<State>> {
135135
return disposables;
136136
}
137137

138-
protected override onMessageReceived(e: MessageEvent) {
139-
const msg = e.data as IpcMessage;
140-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
141-
138+
protected override onMessageReceived(msg: IpcMessage) {
142139
switch (msg.method) {
143140
// case DidChangeRichStateNotificationType.method:
144141
// onIpc(DidChangeRichStateNotificationType, msg, params => {
@@ -222,7 +219,7 @@ export class PatchDetailsApp extends App<Serialized<State>> {
222219
break;
223220

224221
default:
225-
super.onMessageReceived?.(e);
222+
super.onMessageReceived?.(msg);
226223
}
227224
}
228225

src/webviews/apps/plus/timeline/timeline.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ export class TimelineApp extends App<State> {
4848
return disposables;
4949
}
5050

51-
protected override onMessageReceived(e: MessageEvent) {
52-
const msg = e.data as IpcMessage;
53-
51+
protected override onMessageReceived(msg: IpcMessage) {
5452
switch (msg.method) {
5553
case DidChangeNotificationType.method:
56-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
57-
5854
onIpc(DidChangeNotificationType, msg, params => {
5955
this.state = params.state;
6056
this.setState(this.state);
@@ -63,7 +59,7 @@ export class TimelineApp extends App<State> {
6359
break;
6460

6561
default:
66-
super.onMessageReceived?.(e);
62+
super.onMessageReceived?.(msg);
6763
}
6864
}
6965

src/webviews/apps/rebase/rebase.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*global document window*/
22
import './rebase.scss';
33
import Sortable from 'sortablejs';
4+
import type { IpcMessage } from '../../protocol';
45
import { onIpc } from '../../protocol';
56
import type { RebaseEntry, RebaseEntryAction, State } from '../../rebase/protocol';
67
import {
@@ -318,13 +319,9 @@ class RebaseEditor extends App<State> {
318319
});
319320
}
320321

321-
protected override onMessageReceived(e: MessageEvent) {
322-
const msg = e.data;
323-
322+
protected override onMessageReceived(msg: IpcMessage) {
324323
switch (msg.method) {
325324
case DidChangeNotificationType.method:
326-
this.log(`onMessageReceived(${msg.id}): name=${msg.method}`);
327-
328325
onIpc(DidChangeNotificationType, msg, params => {
329326
this.state = params.state;
330327
this.setState(this.state);
@@ -333,7 +330,7 @@ class RebaseEditor extends App<State> {
333330
break;
334331

335332
default:
336-
super.onMessageReceived?.(e);
333+
super.onMessageReceived?.(msg);
337334
}
338335
}
339336

0 commit comments

Comments
 (0)