Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #1108

Open
5 tasks done
carloscuesta opened this issue May 30, 2023 · 1 comment
Open
5 tasks done

Performance improvements #1108

carloscuesta opened this issue May 30, 2023 · 1 comment

Comments

@carloscuesta
Copy link
Owner

carloscuesta commented May 30, 2023

Describe the bug

Hey! 👋🏼

Our cli can be improved when running and executing commands. In some scenarios and depending on the operating system some commands can take up to 1s to give some output.

See: #1096

Reproduction

This can be reproduced using the time command:

time gitmoji --help
time gitmoji --list
time gitmoji --search bug

As a result you'll get an output with the seconds each operation take to complete (for the given commands you'll get something like:

gitmoji --help  0.41s user 0.08s system 115% cpu 0.425 total
gitmoji --list  0.46s user 0.10s system 62% cpu 0.900 total
gitmoji --search bug  0.45s user 0.08s system 119% cpu 0.448 total

Additional context

We should explore the cli to understand if we can apply any improvements that impact the overall time commands take to complete.

System Info

N/A

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating duplicates.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@segersniels
Copy link
Collaborator

segersniels commented Jun 6, 2023

Using dynamic imports might result in some easy wins for the initial startup.

gitmoji --help  0.41s user 0.06s system 108% cpu 0.426 total
node lib/cli.js --help  0.17s user 0.03s system 98% cpu 0.197 total
diff --git a/src/cli.js b/src/cli.js
index 4982d27..4aba009 100755
--- a/src/cli.js
+++ b/src/cli.js
@@ -6,7 +6,6 @@ import { readFileSync } from 'fs'
 
 import FLAGS from '@constants/flags'
 import findGitmojiCommand from '@utils/findGitmojiCommand'
-import commands from './commands'
 
 const packageJson: Object = readFileSync(
   new URL('../package.json', import.meta.url)
@@ -56,14 +55,18 @@ const cli = meow(
 )
 
 export const options = ({
-  [FLAGS.COMMIT]: (options: Object) => commands.commit(options),
-  [FLAGS.CONFIG]: () => commands.config(),
-  [FLAGS.HOOK]: (options: Object) => commands.commit(options),
-  [FLAGS.INIT]: () => commands.createHook(),
-  [FLAGS.LIST]: () => commands.list(),
-  [FLAGS.REMOVE]: () => commands.removeHook(),
-  [FLAGS.SEARCH]: (options: Object) => commands.search(options),
-  [FLAGS.UPDATE]: () => commands.update()
+  [FLAGS.COMMIT]: async (options: Object) =>
+    (await import('./commands/commit')).default(options),
+  [FLAGS.CONFIG]: async () => (await import('./commands/config')).default(),
+  [FLAGS.HOOK]: async (options: Object) =>
+    (await import('./commands/commit')).default(options),
+  [FLAGS.INIT]: async () => (await import('./commands/hook')).default.create(),
+  [FLAGS.LIST]: async () => (await import('./commands/list')).default(),
+  [FLAGS.REMOVE]: async () =>
+    (await import('./commands/hook')).default.remove(),
+  [FLAGS.SEARCH]: async (options: Object) =>
+    (await import('./commands/search')).default(options),
+  [FLAGS.UPDATE]: async () => (await import('./commands/update')).default()
 }: { [$Values<typeof FLAGS>]: Function })
 
 findGitmojiCommand(cli, options)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants