Refactor: 消除 _setActiveComponents 中的内部无效遍历

Aperta
#2,954 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
32/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
game-dev

Direzione di ricerca

Start in the _setActiveComponents loop and the removeChild path that calls _traverseSetOwnerScene(entity, null), plus the activeChangedComponents array they share; PR #2948 introduced the two-phase children-first dispatch. Read how the scene-null guard skips components, then work out how to avoid visiting them without changing the children-to-parent callback order. Done means fewer wasted iterations with the existing dispatch-order behaviour still intact, which needs the project's test suite to confirm.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

概述

PR #2948 通过 children-first 遍历 + scene null guard 修复了 #2947 的崩溃问题,用户侧回调行为完全正确。但两阶段设计导致内部无效遍历:被早期回调的 removeChild 清除了 _scene 的组件仍然进入 _setActiveComponents 循环,只是被 guard 跳过:

```typescript
if (!isActive && !component._entity._scene) continue; // 无效遍历
```

约束

  • 不能改变派发时序:当前是 children-first 收集、统一派发,回调顺序为 children → parent,必须保持

方案方向

在保持两阶段架构和派发时序的前提下,减少无效遍历。例如:

  • 在 removeChild → _traverseSetOwnerScene(entity, null) 时,同步从 activeChangedComponents 数组中移除对应组件(或置 null 标记跳过)
  • 或在组件上加轻量标记位,让循环体判断更高效

关联

  • 优化 #2948 / #2947 的临时方案
Lingua principale
TypeScript
Stelle
5.9k
Fork
413
Merge medio
16h 17m
PR unite (30g)
41

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di galacean/engine

Tutte le issue di galacean/engine

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.