Skip to content

screenshot コマンドの実行時間が長い (37s) #83

@bigdra50

Description

@bigdra50

現象

u screenshot (source=game) の実行に 37秒かかる。

$ u -i 3 screenshot
[Retry] INSTANCE_BUSY (attempt 1, waiting 500ms)
[Retry] INSTANCE_BUSY (attempt 2, waiting 1000ms)
[Retry] INSTANCE_BUSY (attempt 3, waiting 2000ms)
[OK] Screenshot captured: ...

遅延の内訳(推定)

要因 時間
INSTANCE_BUSY リトライ 3回 ~3.5s
ソケットタイムアウト (5s) × 複数回? 不明
Unity 側 CaptureGameViewAsync 不明
合計 37s

遅延要因の候補

1. INSTANCE_BUSY リトライ

他コマンドが先に処理中だった可能性。3回リトライで 3.5s はリトライ自体の仕様通り。

2. Unity 側 CaptureGameViewAsync の構造的な遅さ

  • Screenshot.csCaptureGameViewAsyncEditorApplication.update ループで実行
  • 2フレーム待ち → ScreenCapture.CaptureScreenshot → ファイル存在ポーリング
  • エディタのフレームレートに依存(エディタが非フォーカス時は更新頻度が極端に低い)
  • PlayMode 必須

3. ソケットタイムアウト

  • デフォルト timeout=5.0s
  • Unity 側の処理が長いとソケット読み取りでタイムアウト → リトライの可能性

調査方針

  • --verbose で request/response のタイムスタンプを確認し、ボトルネック特定
  • camera source との比較(同期・フォーカス不要で高速なはず)
  • エディタフォーカス有無での game source の速度差

改善案

  • デフォルト source を gamecamera に変更検討(camera は同期・フォーカス不要)
  • CaptureGameViewAsync のフレーム待ち・ポーリング間隔の改善
  • EditorApplication.QueuePlayerLoopUpdate() の追加呼び出しでエディタ更新を促進

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions