perf(network): repeated copies and allocations in the packet send and receive paths

未關閉
#507 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
53/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
typescript
領域
networking

研究方向

Start with the five listed locations in modules/network/src/shared/channels.ts, modules/network/src/server/utils.ts, modules/network/src/server/network-server.ts, modules/network/src/shared/packet.ts, and modules/network/src/server/peer-host.ts; trace how packet buffers and per-tick containers move through send, receive, and dispatch. The issue identifies the repeated copies and allocations to address. Done when those paths avoid the described unnecessary copies and rebuilds while packet results remain correct; the issue names no tests to run.

由索引模型根據 Issue 內容生成。

描述

enhancement modules:network
Which package or utils is this feature request for?

network

Feature

TCP receive copies each frame twice (rawDataToUint8Array, then slice(1)), send copies it twice, and PeerHost.send copies it for each recipient. getReceivedPackets() rebuilds arrays each tick, and dispatch spreads the listener set. Results are correct, but this is garbage on every packet and tick.

Where:

Evidence:

return { channel, data: frame.slice(1) };
merged.set(clientId, [...(merged.get(clientId) ?? []), ...packets]);
for (const listener of [...listeners]) this.call(listener, received, ctx);
Ideal solution or implementation

Use subarray(1) on frames the code owns, skip copies of inputs that are already Uint8Array, and reuse containers between ticks.

Alternative solutions or implementations

No response

Other context

Found during a code audit of main at be72076.

主要語言
TypeScript
星號
7
分支
2
平均合併
1 天 17 小時
30 天內合併 PR
17

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

NanoForge-dev/Engine 的其他 Issue

查看 NanoForge-dev/Engine 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。