Skip to content

Faster startup (4/4): Lazy imports and V8 compile cache#7054

Draft
gonzaloriestra wants to merge 1 commit intofaster-startup-3from
faster-startup-4
Draft

Faster startup (4/4): Lazy imports and V8 compile cache#7054
gonzaloriestra wants to merge 1 commit intofaster-startup-3from
faster-startup-4

Conversation

@gonzaloriestra
Copy link
Contributor

WHY are these changes introduced?

The CLI requires too much time to start working, it feels slow

WHAT is this pull request doing?

Defers heavy module imports to point of use across the codebase and enables V8 compile caching for faster subsequent runs.

  • base-command.ts: lazy imports for ui.js (600KB React/Ink), error-handler.js, notifications-system.js, environments.js — only loaded when actually needed
  • prerun hook: parallel imports via Promise.all for analytics, notifications, and package-manager modules
  • postrun hook: lazy imports for analytics, deprecations, and output modules
  • node-package-manager.ts: lazy latest-version import (~113ms saved)
  • context/local.ts: lazy fs.js and system.js to break circular dependency chains
  • is-global.ts: lazy imports for output.js, system.js, version.js, ui.js
  • custom-oclif-loader.ts: fire-and-forget init hooks via runHook override so app-init and hydrogen-init run in background
  • V8 compile cache: module.enableCompileCache() in dev.js/run.js caches bytecode between runs, eliminating ~30ms compile overhead

Combined improvement: ~130ms across all commands

How to test your changes?

  • All commands work correctly (hooks fire in background)
  • shopify version / shopify help return correct output
  • Second run is faster than first (V8 cache warm)

Measuring impact

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Made with Cursor

Copy link
Contributor Author

gonzaloriestra commented Mar 19, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Defer heavy module imports to point of use across the codebase:
- base-command: lazy ui.js (600KB React/Ink), error-handler, notifications
- prerun hook: parallel imports via Promise.all
- postrun hook: lazy analytics and deprecations
- node-package-manager: lazy latest-version import
- context/local: lazy fs.js and system.js (break circular deps)
- is-global: lazy output.js, system.js, version.js, ui.js
- custom-oclif-loader: fire-and-forget init hooks via runHook override

Enable V8 compile cache via module.enableCompileCache() in dev.js/run.js,
caching bytecode between runs to eliminate ~30ms compile overhead.

Combined improvement: ~130ms across all commands

Made-with: Cursor
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