Skip to content

enhance: 起動からlistenまでかかる時間を減らす#1410

Merged
u1-liquid merged 1 commit intomainfrom
01-24-enhance_listen_
Jan 24, 2026
Merged

enhance: 起動からlistenまでかかる時間を減らす#1410
u1-liquid merged 1 commit intomainfrom
01-24-enhance_listen_

Conversation

@u1-liquid
Copy link
Member

@u1-liquid u1-liquid commented Jan 23, 2026

What

Implemented dynamic imports in boot process to reduce cold-start time in clustered environments. This change ensures that worker-side code is not loaded in the master process and vice versa.

Why

This optimization reduces the initial load time by preventing unnecessary module imports. Previously, both master and worker code was being imported regardless of which process was running, causing redundant loading of the full module graph.

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

Summary by CodeRabbit

リリースノート

  • Refactor
    • アプリケーション起動プロセスを改善しました。これにより、バックエンドサーバーおよびジョブキューシステムの起動時間が著しく短縮され、全体的なシステムパフォーマンスと応答性が向上します。ユーザーはアプリケーション起動がより迅速で安定した快適なものになることを体験できるようになります。

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

2つのブートストラップモジュールにおいて、静的なトップレベルインポートを動的なランタイムインポートに置き換えました。NestJSサービスとマスター/ワーカープロセスモジュールの遅延読み込みにより、初期ロード時間を削減します。

Changes

Cohort / File(s) Summary
Boot Module Lazy Imports
packages/backend/src/boot/common.ts
server()とjobQueue()関数内のNestJSサービスインポート(MainModule、ServerService、ChartManagementService、QueueProcessorModule等)を動的インポートに変更。モジュール解決を必要時点まで遅延させます。
Entry Point Lazy Imports
packages/backend/src/boot/entry.ts
クラスタプライマリ時にmasterMainを、ワーカー時にworkerMainを遅延読み込みするよう変更。コメント追加で遅延読み込みの根拠を説明します。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰✨ モジュールは今、歩みを遅く、
必要な時まで目覚めずにいる。
スタート時間は軽やかに、
遅延の魔法で読み込み最適化!
バニー博士より、コードは喜ぶ。 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PRのタイトルは起動からlistenまでの時間短縮という変更の主要な目的を正確に反映しており、変更内容と一致しています。
Description check ✅ Passed PRの説明はテンプレートの主要なセクション(What、Why)を含んでおり、変更の目的と理由が明確に記述されています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 01-24-enhance_listen_

Comment @coderabbitai help to get the list of available commands and usage tips.

@snyk-io
Copy link

snyk-io bot commented Jan 23, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@u1-liquid
Copy link
Member Author

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

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/backend/src/boot/common.ts 0.00% 9 Missing ⚠️
packages/backend/src/boot/entry.ts 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@u1-liquid u1-liquid marked this pull request as ready for review January 23, 2026 18:52
Copilot AI review requested due to automatic review settings January 23, 2026 18:52
@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Overview

Greptile Summary

このPRは、クラスタリング環境でのコールドスタート時間を削減するため、静的インポートを動的インポートに変更する最適化を実装しています。

主な変更点:

  • entry.ts: masterMainworkerMainの動的インポート化により、マスタープロセスでワーカー側のコードが、ワーカープロセスでマスター側のコードがロードされることを防止
  • common.ts: server()jobQueue()関数内でMainModuleServerServiceQueueProcessorModule等の重いモジュールを動的インポート化し、各関数が呼ばれるまでモジュール読み込みを遅延

効果:
この変更により、クラスタリング有効時に各プロセスは自身に必要なモジュールのみをロードするため、起動時のモジュールグラフ全体の読み込みが回避され、起動時間が短縮されます。

実装の妥当性:

  • 動的インポートの配置は論理的に正しく、各プロセスタイプの条件分岐に適切に対応
  • コードの機能性は維持されており、既存のロジックに影響なし

Confidence Score: 5/5

  • このPRは安全にマージ可能で、リスクは最小限です
  • 動的インポートの実装が正確で論理的に正しく、既存の機能を損なわずにパフォーマンスの最適化を実現しています。変更は限定的で、コードの可読性も維持されており、テストも問題なく通過すると考えられます
  • 特に注意が必要なファイルはありません

Important Files Changed

Filename Overview
packages/backend/src/boot/entry.ts masterMainとworkerMainを動的インポートに変更し、クラスタリング環境での起動時間を最適化
packages/backend/src/boot/common.ts server()とjobQueue()関数内で依存モジュールを動的にインポートし、不要なモジュール読み込みを回避

Sequence Diagram

sequenceDiagram
    participant Entry as entry.ts
    participant Master as master.ts
    participant Worker as worker.ts
    participant Common as common.ts
    participant Modules as Heavy Modules<br/>(MainModule, ServerService,<br/>QueueProcessorModule, etc)

    Note over Entry: プロセス開始
    
    alt isPrimary or disableClustering
        Entry->>Entry: 動的インポート: masterMain
        Entry->>Master: masterMain()
        Master->>Master: greet(), showEnvironment()
        
        alt onlyQueue
            Master->>Common: jobQueue()
            Common->>Common: 動的インポート: QueueProcessorModule等
            Common->>Modules: QueueProcessorModule読み込み
        else onlyServer or default
            Master->>Common: server()
            Common->>Common: 動的インポート: MainModule等
            Common->>Modules: MainModule, ServerService読み込み
        end
        
        opt クラスタリング有効
            Master->>Master: spawnWorkers()
            Master->>Entry: cluster.fork()
        end
    end
    
    alt isWorker
        Entry->>Entry: 動的インポート: workerMain
        Entry->>Worker: workerMain()
        
        alt onlyServer
            Worker->>Common: server()
            Common->>Common: 動的インポート: MainModule等
            Common->>Modules: MainModule, ServerService読み込み
        else onlyQueue or default
            Worker->>Common: jobQueue()
            Common->>Common: 動的インポート: QueueProcessorModule等
            Common->>Modules: QueueProcessorModule読み込み
        end
        
        Worker->>Entry: process.send('ready')
    end
    
    Note over Entry,Modules: 最適化効果: 各プロセスは必要なモジュールのみロード
Loading

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a performance optimization to reduce cold-start time in clustered environments by converting static imports to dynamic imports. The changes ensure that master process code is not loaded in worker processes and vice versa, which reduces unnecessary module loading when processes are forked.

Changes:

  • Converted static imports of masterMain and workerMain to dynamic imports in entry.ts, loaded only when needed based on process type
  • Converted static imports in common.ts functions to dynamic imports, allowing server and queue processor modules to be loaded only when their respective functions are called

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/backend/src/boot/entry.ts Replaced static imports of master.js and worker.js with dynamic imports within their respective conditional blocks
packages/backend/src/boot/common.ts Replaced static imports with dynamic imports inside server() and jobQueue() functions to defer module loading

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@u1-liquid u1-liquid merged commit aac8f50 into main Jan 24, 2026
36 of 38 checks passed
@u1-liquid u1-liquid deleted the 01-24-enhance_listen_ branch January 24, 2026 01:14
kakkokari-gtyih pushed a commit to kakkokari-gtyih/misskey that referenced this pull request Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants