Skip to content

Conversation

@joehan
Copy link
Contributor

@joehan joehan commented Nov 24, 2025

Description

Lazy load commands as needed, instead of 'require'ing them all at once at the start of every command

Scenarios Tested

Manually validated that commands still work, and check that 'firebase' and 'firebase help' still work. Also tested out flags, both that expected ones are allowed and unexpected ones as not:
Screenshot 2025-11-25 at 3 08 44 PM

Also tested out that nested commands still work - iefirebase target and firebase target:apply

Added some timer code, and found that previously, we would do about 800ms of loading before every command - now it is <10ms.
Before this change - every commands would take about 800ms upfront:
Screenshot 2025-11-24 at 2 25 19 PM
After - different commands take differing amounts of time, but range from >10ms (for smaller ones) to ~300ms (for the ones with the largest dep trees)
Screenshot 2025-11-24 at 2 33 59 PM

Finally, I also validated that require('firebase-tools').getCommand("commandName") still works. IDK if anyone in the world uses this, but we technically export it (and use it in the barely used firebase ext command)

google-labs-jules bot and others added 4 commits November 21, 2025 22:50
- Updated `src/commands/index.ts` to make `loadCommand` return a lazy runner that only `require`s and registers the command when executed or explicitly loaded.
- Updated `src/index.ts` to handle lazy loading in the catch-all command handler by traversing the `client` object and loading the matching command before re-parsing arguments.
- Updated `src/bin/cli.ts` to load all commands when no arguments are provided (global help), ensuring the help text is fully populated.
- Added cycle detection to the `loadAll` logic to handle circular references in the `client` object.
- Updated `src/commands/index.ts` to make `loadCommand` return a lazy runner that only `require`s and registers the command when executed or explicitly loaded.
- Updated `src/index.ts` to handle lazy loading in the catch-all command handler by traversing the `client` object and loading the matching command before re-parsing arguments.
- Updated `src/bin/cli.ts` to load all commands when no arguments are provided (global help), ensuring the help text is fully populated.
- Added cycle detection to the `loadAll` logic to handle circular references in the `client` object.
- Added `scripts/benchmark_load.ts` to measure command load time.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @joehan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant performance optimization by implementing lazy loading for Firebase CLI commands. Previously, all commands were loaded at startup, leading to noticeable delays. With this change, commands are now loaded on demand, dramatically reducing the initial overhead and improving the responsiveness of the CLI for most operations. The core logic involves refactoring how commands are registered and executed, with special handling for help commands and direct command invocations to maintain functionality while maximizing performance gains.

Highlights

  • Performance Improvement: Implemented lazy loading for CLI commands, drastically reducing startup time from approximately 800ms to less than 10ms for smaller commands and around 300ms for commands with larger dependency trees.
  • Lazy Command Loading Mechanism: Introduced a new load function attached to command runners in src/commands/index.ts, allowing commands to be registered and loaded only when explicitly invoked.
  • Conditional Eager Loading: Modified src/bin/cli.ts to eagerly load all commands only when firebase or firebase help is executed, ensuring full command availability for help displays.
  • Dynamic Command Resolution: Updated src/index.ts to dynamically resolve and load specific commands when they are directly called, ensuring the correct command is initialized before execution.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces lazy loading for commands to significantly improve CLI startup time. The approach is solid, but there are a couple of issues to address. First, the implementation in src/commands/index.ts can lead to commands being registered multiple times, which is inefficient and could cause subtle bugs. I've suggested a refactor to prevent this. Second, the handling of the help command in src/bin/cli.ts has a regression that breaks firebase help <command>. I've provided a fix for this as well. Addressing these points will make this performance improvement robust.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant