From 48f926c6a33c30f856238d3f2a14d9f121baa945 Mon Sep 17 00:00:00 2001 From: almouro Date: Fri, 5 Apr 2024 12:13:01 +0200 Subject: [PATCH] fix(cli): improve cli performance a little bit When running anything other than measure, we gain a little bit of time when running CLI --- packages/commands/measure/package.json | 4 +- .../commands/measure/src/server/ServerApp.tsx | 10 +++- packages/commands/measure/src/server/bin.tsx | 13 ++--- yarn.lock | 58 ++++++------------- 4 files changed, 32 insertions(+), 53 deletions(-) diff --git a/packages/commands/measure/package.json b/packages/commands/measure/package.json index c6659949..15177d53 100644 --- a/packages/commands/measure/package.json +++ b/packages/commands/measure/package.json @@ -18,10 +18,10 @@ "@perf-profiler/types": "^0.7.0", "commander": "^12.0.0", "cors": "^2.8.5", - "express": "^4.18.3", + "express": "^4.19.2", "ink": "^3.2.0", "react": "^18.0.0", - "socket.io": "^4.7.4" + "socket.io": "^4.7.5" }, "devDependencies": { "@mui/icons-material": "^5.15.12", diff --git a/packages/commands/measure/src/server/ServerApp.tsx b/packages/commands/measure/src/server/ServerApp.tsx index ca55da53..4970a8e2 100644 --- a/packages/commands/measure/src/server/ServerApp.tsx +++ b/packages/commands/measure/src/server/ServerApp.tsx @@ -10,7 +10,7 @@ import { SocketType, SocketServer } from "./socket/socketInterface"; import { HostAndPortInfo } from "./components/HostAndPortInfo"; import { getWebAppUrl } from "./constants"; import { ServerSocketConnectionApp } from "./ServerSocketConnectionApp"; -import { useInput } from "ink"; +import { render, useInput } from "ink"; import { profiler } from "@perf-profiler/profiler"; const pathToDist = path.join(__dirname, "../../dist"); @@ -93,3 +93,11 @@ export const ServerApp = ({ port }: ServerAppProps) => { ); }; + +export const runServerApp = (port: number) => { + render( + , + // handle it ourselves in the profiler to kill child processes thanks to useCleanupOnManualExit + { exitOnCtrlC: false } + ); +}; diff --git a/packages/commands/measure/src/server/bin.tsx b/packages/commands/measure/src/server/bin.tsx index df13cf17..4d0442b9 100644 --- a/packages/commands/measure/src/server/bin.tsx +++ b/packages/commands/measure/src/server/bin.tsx @@ -1,9 +1,6 @@ #!/usr/bin/env node import { program } from "commander"; -import { ServerApp } from "./ServerApp"; -import { render } from "ink"; -import React from "react"; import { DEFAULT_PORT } from "./constants"; program @@ -16,13 +13,11 @@ Main usage: flashlight measure` ) .option("-p, --port [port]", "Specify the port number for the server") - .action((options) => { + .action(async (options) => { const port = Number(options.port) || DEFAULT_PORT; - render( - , - // handle it ourselves in the profiler to kill child processes thanks to useCleanupOnManualExit - { exitOnCtrlC: false } - ); + // measure command can be a bit slow to load since we run ink, express and socket.io, so lazy load it + const { runServerApp } = await import("./ServerApp"); + runServerApp(port); }); program.parse(); diff --git a/yarn.lock b/yarn.lock index 9d8be664..a167f72a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4986,10 +4986,10 @@ cookie-signature@1.0.6: resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ== -cookie@0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" - integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== +cookie@0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.6.0.tgz#2798b04b071b0ecbff0dbb62a505a8efa4e19051" + integrity sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw== cookie@~0.4.1: version "0.4.2" @@ -5915,6 +5915,7 @@ eslint-module-utils@^2.8.0: "eslint-plugin-custom-rules@link:./packages/eslint-plugin-flashlight-eslint-rules/dist": version "0.0.0" + uid "" eslint-plugin-import@^2.26.0: version "2.29.1" @@ -6172,17 +6173,17 @@ exponential-backoff@^3.1.1: resolved "https://registry.yarnpkg.com/exponential-backoff/-/exponential-backoff-3.1.1.tgz#64ac7526fe341ab18a39016cd22c787d01e00bf6" integrity sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw== -express@^4.18.3: - version "4.18.3" - resolved "https://registry.yarnpkg.com/express/-/express-4.18.3.tgz#6870746f3ff904dee1819b82e4b51509afffb0d4" - integrity sha512-6VyCijWQ+9O7WuVMTRBTl+cjNNIzD5cY5mQ1WM8r/LEkI2u8EYpOotESNwzNlyCn3g+dmjKYI6BmNneSr/FSRw== +express@^4.19.2: + version "4.19.2" + resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465" + integrity sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q== dependencies: accepts "~1.3.8" array-flatten "1.1.1" body-parser "1.20.2" content-disposition "0.5.4" content-type "~1.0.4" - cookie "0.5.0" + cookie "0.6.0" cookie-signature "1.0.6" debug "2.6.9" depd "2.0.0" @@ -10922,10 +10923,10 @@ socket.io-parser@~4.2.4: "@socket.io/component-emitter" "~3.1.0" debug "~4.3.1" -socket.io@^4.7.4: - version "4.7.4" - resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.7.4.tgz#2401a2d7101e4bdc64da80b140d5d8b6a8c7738b" - integrity sha512-DcotgfP1Zg9iP/dH9zvAQcWrE0TtbMVwXmlV4T4mqsvY+gw+LqUGPfx2AoVyRk0FLME+GQhufDMyacFmw7ksqw== +socket.io@^4.7.5: + version "4.7.5" + resolved "https://registry.yarnpkg.com/socket.io/-/socket.io-4.7.5.tgz#56eb2d976aef9d1445f373a62d781a41c7add8f8" + integrity sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA== dependencies: accepts "~1.3.4" base64id "~2.0.0" @@ -11102,16 +11103,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -"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: +"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: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -11194,14 +11186,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -12176,7 +12161,7 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -12194,15 +12179,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"