Skip to content

Commit f646064

Browse files
authored
fix(cli): improve cli performance a little bit (#269)
When running anything other than measure, we gain a little bit of time when running CLI
1 parent 20a9d69 commit f646064

File tree

4 files changed

+32
-53
lines changed

4 files changed

+32
-53
lines changed

packages/commands/measure/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"@perf-profiler/types": "^0.7.0",
1919
"commander": "^12.0.0",
2020
"cors": "^2.8.5",
21-
"express": "^4.18.3",
21+
"express": "^4.19.2",
2222
"ink": "^3.2.0",
2323
"react": "^18.0.0",
24-
"socket.io": "^4.7.4"
24+
"socket.io": "^4.7.5"
2525
},
2626
"devDependencies": {
2727
"@mui/icons-material": "^5.15.12",

packages/commands/measure/src/server/ServerApp.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SocketType, SocketServer } from "./socket/socketInterface";
1010
import { HostAndPortInfo } from "./components/HostAndPortInfo";
1111
import { getWebAppUrl } from "./constants";
1212
import { ServerSocketConnectionApp } from "./ServerSocketConnectionApp";
13-
import { useInput } from "ink";
13+
import { render, useInput } from "ink";
1414
import { profiler } from "@perf-profiler/profiler";
1515

1616
const pathToDist = path.join(__dirname, "../../dist");
@@ -93,3 +93,11 @@ export const ServerApp = ({ port }: ServerAppProps) => {
9393
<HostAndPortInfo url={webAppUrl} />
9494
);
9595
};
96+
97+
export const runServerApp = (port: number) => {
98+
render(
99+
<ServerApp port={port} />,
100+
// handle it ourselves in the profiler to kill child processes thanks to useCleanupOnManualExit
101+
{ exitOnCtrlC: false }
102+
);
103+
};
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#!/usr/bin/env node
22

33
import { program } from "commander";
4-
import { ServerApp } from "./ServerApp";
5-
import { render } from "ink";
6-
import React from "react";
74
import { DEFAULT_PORT } from "./constants";
85

96
program
@@ -16,13 +13,11 @@ Main usage:
1613
flashlight measure`
1714
)
1815
.option("-p, --port [port]", "Specify the port number for the server")
19-
.action((options) => {
16+
.action(async (options) => {
2017
const port = Number(options.port) || DEFAULT_PORT;
21-
render(
22-
<ServerApp port={port} />,
23-
// handle it ourselves in the profiler to kill child processes thanks to useCleanupOnManualExit
24-
{ exitOnCtrlC: false }
25-
);
18+
// measure command can be a bit slow to load since we run ink, express and socket.io, so lazy load it
19+
const { runServerApp } = await import("./ServerApp");
20+
runServerApp(port);
2621
});
2722

2823
program.parse();

yarn.lock

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4997,10 +4997,10 @@ [email protected]:
49974997
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
49984998
integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==
49994999

5000-
cookie@0.5.0:
5001-
version "0.5.0"
5002-
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b"
5003-
integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==
5000+
cookie@0.6.0:
5001+
version "0.6.0"
5002+
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051"
5003+
integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==
50045004

50055005
cookie@~0.4.1:
50065006
version "0.4.2"
@@ -5926,6 +5926,7 @@ eslint-module-utils@^2.8.0:
59265926

59275927
"eslint-plugin-custom-rules@link:./packages/eslint-plugin-flashlight-eslint-rules/dist":
59285928
version "0.0.0"
5929+
uid ""
59295930

59305931
eslint-plugin-import@^2.26.0:
59315932
version "2.29.1"
@@ -6183,17 +6184,17 @@ exponential-backoff@^3.1.1:
61836184
resolved "https://registry.yarnpkg.com/exponential-backoff/-/exponential-backoff-3.1.1.tgz#64ac7526fe341ab18a39016cd22c787d01e00bf6"
61846185
integrity sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==
61856186

6186-
express@^4.18.3:
6187-
version "4.18.3"
6188-
resolved "https://registry.yarnpkg.com/express/-/express-4.18.3.tgz#6870746f3ff904dee1819b82e4b51509afffb0d4"
6189-
integrity sha512-6VyCijWQ+9O7WuVMTRBTl+cjNNIzD5cY5mQ1WM8r/LEkI2u8EYpOotESNwzNlyCn3g+dmjKYI6BmNneSr/FSRw==
6187+
express@^4.19.2:
6188+
version "4.19.2"
6189+
resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465"
6190+
integrity sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==
61906191
dependencies:
61916192
accepts "~1.3.8"
61926193
array-flatten "1.1.1"
61936194
body-parser "1.20.2"
61946195
content-disposition "0.5.4"
61956196
content-type "~1.0.4"
6196-
cookie "0.5.0"
6197+
cookie "0.6.0"
61976198
cookie-signature "1.0.6"
61986199
debug "2.6.9"
61996200
depd "2.0.0"
@@ -10933,10 +10934,10 @@ socket.io-parser@~4.2.4:
1093310934
"@socket.io/component-emitter" "~3.1.0"
1093410935
debug "~4.3.1"
1093510936

10936-
socket.io@^4.7.4:
10937-
version "4.7.4"
10938-
resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.7.4.tgz#2401a2d7101e4bdc64da80b140d5d8b6a8c7738b"
10939-
integrity sha512-DcotgfP1Zg9iP/dH9zvAQcWrE0TtbMVwXmlV4T4mqsvY+gw+LqUGPfx2AoVyRk0FLME+GQhufDMyacFmw7ksqw==
10937+
socket.io@^4.7.5:
10938+
version "4.7.5"
10939+
resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.7.5.tgz#56eb2d976aef9d1445f373a62d781a41c7add8f8"
10940+
integrity sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==
1094010941
dependencies:
1094110942
accepts "~1.3.4"
1094210943
base64id "~2.0.0"
@@ -11113,16 +11114,7 @@ string-length@^4.0.1:
1111311114
char-regex "^1.0.2"
1111411115
strip-ansi "^6.0.0"
1111511116

11116-
"string-width-cjs@npm:string-width@^4.2.0":
11117-
version "4.2.3"
11118-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
11119-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
11120-
dependencies:
11121-
emoji-regex "^8.0.0"
11122-
is-fullwidth-code-point "^3.0.0"
11123-
strip-ansi "^6.0.1"
11124-
11125-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
11117+
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
1112611118
version "4.2.3"
1112711119
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1112811120
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -11205,14 +11197,7 @@ string_decoder@~1.1.1:
1120511197
dependencies:
1120611198
safe-buffer "~5.1.0"
1120711199

11208-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
11209-
version "6.0.1"
11210-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
11211-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
11212-
dependencies:
11213-
ansi-regex "^5.0.1"
11214-
11215-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
11200+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1121611201
version "6.0.1"
1121711202
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1121811203
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -12187,7 +12172,7 @@ wordwrap@^1.0.0:
1218712172
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
1218812173
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
1218912174

12190-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
12175+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1219112176
version "7.0.0"
1219212177
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1219312178
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -12205,15 +12190,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
1220512190
string-width "^4.1.0"
1220612191
strip-ansi "^6.0.0"
1220712192

12208-
wrap-ansi@^7.0.0:
12209-
version "7.0.0"
12210-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
12211-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
12212-
dependencies:
12213-
ansi-styles "^4.0.0"
12214-
string-width "^4.1.0"
12215-
strip-ansi "^6.0.0"
12216-
1221712193
wrap-ansi@^8.1.0:
1221812194
version "8.1.0"
1221912195
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)