Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c62431

Browse files
Output panel optimisation (#1058)
* test interval for output panel * create buffer provider * output panel buffer corrections * output buffer cleanup * code cleanup
1 parent a804766 commit 4c62431

File tree

2 files changed

+83
-24
lines changed

2 files changed

+83
-24
lines changed

‎arduino-ide-extension/src/node/core-service-impl.ts‎

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import { firstToUpperCase, firstToLowerCase } from '../common/utils';
2525
import { Port } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb';
2626
import { nls } from '@theia/core';
2727
import { MonitorManager } from './monitor-manager';
28+
import { SimpleBuffer } from './utils/simple-buffer';
2829

30+
const FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS = 32;
2931
@injectable()
3032
export class CoreServiceImpl extends CoreClientAware implements CoreService {
3133
@inject(ResponseService)
@@ -73,18 +75,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
7375
this.mergeSourceOverrides(compileReq, options);
7476

7577
const result = client.compile(compileReq);
78+
79+
const compileBuffer = new SimpleBuffer(
80+
this.flushOutputPanelMessages.bind(this),
81+
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
82+
);
7683
try {
7784
await new Promise<void>((resolve, reject) => {
7885
result.on('data', (cr: CompileResponse) => {
79-
this.responseService.appendToOutput({
80-
chunk: Buffer.from(cr.getOutStream_asU8()).toString(),
81-
});
82-
this.responseService.appendToOutput({
83-
chunk: Buffer.from(cr.getErrStream_asU8()).toString(),
84-
});
86+
compileBuffer.addChunk(cr.getOutStream_asU8());
87+
compileBuffer.addChunk(cr.getErrStream_asU8());
88+
});
89+
result.on('error', (error) => {
90+
compileBuffer.clearFlushInterval();
91+
reject(error);
92+
});
93+
result.on('end', () => {
94+
compileBuffer.clearFlushInterval();
95+
resolve();
8596
});
86-
result.on('error', (error) => reject(error));
87-
result.on('end', () => resolve());
8897
});
8998
this.responseService.appendToOutput({
9099
chunk: '\n--------------------------\nCompilation complete.\n',
@@ -174,18 +183,24 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
174183

175184
const result = responseHandler(client, req);
176185

186+
const uploadBuffer = new SimpleBuffer(
187+
this.flushOutputPanelMessages.bind(this),
188+
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
189+
);
177190
try {
178191
await new Promise<void>((resolve, reject) => {
179192
result.on('data', (resp: UploadResponse) => {
180-
this.responseService.appendToOutput({
181-
chunk: Buffer.from(resp.getOutStream_asU8()).toString(),
182-
});
183-
this.responseService.appendToOutput({
184-
chunk: Buffer.from(resp.getErrStream_asU8()).toString(),
185-
});
193+
uploadBuffer.addChunk(resp.getOutStream_asU8());
194+
uploadBuffer.addChunk(resp.getErrStream_asU8());
195+
});
196+
result.on('error', (error) => {
197+
uploadBuffer.clearFlushInterval();
198+
reject(error);
199+
});
200+
result.on('end', () => {
201+
uploadBuffer.clearFlushInterval();
202+
resolve();
186203
});
187-
result.on('error', (error) => reject(error));
188-
result.on('end', () => resolve());
189204
});
190205
this.responseService.appendToOutput({
191206
chunk:
@@ -238,18 +253,25 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
238253
burnReq.setVerify(options.verify);
239254
burnReq.setVerbose(options.verbose);
240255
const result = client.burnBootloader(burnReq);
256+
257+
const bootloaderBuffer = new SimpleBuffer(
258+
this.flushOutputPanelMessages.bind(this),
259+
FLUSH_OUTPUT_MESSAGES_TIMEOUT_MS
260+
);
241261
try {
242262
await new Promise<void>((resolve, reject) => {
243263
result.on('data', (resp: BurnBootloaderResponse) => {
244-
this.responseService.appendToOutput({
245-
chunk: Buffer.from(resp.getOutStream_asU8()).toString(),
246-
});
247-
this.responseService.appendToOutput({
248-
chunk: Buffer.from(resp.getErrStream_asU8()).toString(),
249-
});
264+
bootloaderBuffer.addChunk(resp.getOutStream_asU8());
265+
bootloaderBuffer.addChunk(resp.getErrStream_asU8());
266+
});
267+
result.on('error', (error) => {
268+
bootloaderBuffer.clearFlushInterval();
269+
reject(error);
270+
});
271+
result.on('end', () => {
272+
bootloaderBuffer.clearFlushInterval();
273+
resolve();
250274
});
251-
result.on('error', (error) => reject(error));
252-
result.on('end', () => resolve());
253275
});
254276
} catch (e) {
255277
const errorMessage = nls.localize(
@@ -281,4 +303,10 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
281303
}
282304
}
283305
}
306+
307+
private flushOutputPanelMessages(chunk: string): void {
308+
this.responseService.appendToOutput({
309+
chunk,
310+
});
311+
}
284312
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export class SimpleBuffer {
2+
private chunks: Uint8Array[] = [];
3+
4+
private flushInterval?: NodeJS.Timeout;
5+
6+
constructor(onFlush: (chunk: string) => void, flushTimeout: number) {
7+
this.flushInterval = setInterval(() => {
8+
if (this.chunks.length > 0) {
9+
const chunkString = Buffer.concat(this.chunks).toString();
10+
this.clearChunks();
11+
12+
onFlush(chunkString);
13+
}
14+
}, flushTimeout);
15+
}
16+
17+
public addChunk(chunk: Uint8Array): void {
18+
this.chunks.push(chunk);
19+
}
20+
21+
private clearChunks(): void {
22+
this.chunks = [];
23+
}
24+
25+
public clearFlushInterval(): void {
26+
this.clearChunks();
27+
28+
clearInterval(this.flushInterval);
29+
this.flushInterval = undefined;
30+
}
31+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /