NativeEngine: inline SubmitCommands pays a native -> JS -> native round trip even when nothing is staged
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 74/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- cpp, javascript, typescript
- 領域
- backend, performance
調査の方向性
Start with NativeDataStream._flush in packages/dev/core/src/Engines/Native/nativeDataStream.ts; the suggested small change is to return when _position is zero. Trace the flush callback to NativeDataStream::GetReader in Plugins/NativeEngine/Source/NativeDataStream.h and the three SubmitCommands(info) call sites in NativeEngine.cpp to confirm ordering when commands are staged. Done when empty flushes avoid writeBuffer, staged commands still drain in order, and the relevant tests pass.
索引モデルが issue の本文から書いたものです。
説明
Problem
NativeDataStream::GetReader() always calls the JavaScript flush callback, and the JavaScript side always answers by calling writeBuffer back into native, even when zero words are staged. NativeEngine::SubmitCommands can only see that the stream is empty after that round trip.
Three NativeEngine entry points call SubmitCommands(info) inline before doing their own work, so each call pays two extra JS/native crossings when there is nothing to drain:
NativeEngine::UpdateDynamicVertexBuffer(updateDynamicVertexBuffer: thin-instance, instance, particle and other dynamic vertex buffers updated throughBuffer.update/updateDirectly)NativeEngine::LoadRawTexture(updateRawTextureand raw uploads)NativeEngine::ReadTransformFeedbackBuffer
Raised in https://github.com/BabylonJS/BabylonNative/pull/2071#discussion_r4531300740. #2071 as merged removed the same call from deleteTexture by queueing COMMAND_DELETETEXTURE; the three sites above remain.
Measured
iPhone XS, iOS 18.7, JavaScriptCore without JIT, RelWithDebInfo, on the earlier revision of #2071 in which deleteTexture made this same SubmitCommands(info) call:
| without the call | with the call | |
|---|---|---|
texture.dispose(), 16 per frame |
18.7-19.4 µs | 25.1-26.5 µs |
| 2,000 disposes in one task | 24-26 ms | 35-36 ms |
Time Profiler attributed 137 of the 171 ms sampled under DeleteTexture to the SubmitCommands(info) line. The top leaves were the JSC::JSLockHolder constructor and destructor: the cost is the round trip, not command decoding.
Not measured
The three remaining call sites have not been profiled. They run the same code, so the expectation is the same cost per call on that device (about 6-7 µs, the difference in the first row); a scene that updates N dynamic vertex buffers per frame would pay it N times. This is an extrapolation, not a measurement. Desktop and JIT-enabled engines have not been measured.
Platform / backend
Independent of the graphics backend. The cost was measured on iOS with JavaScriptCore without JIT. Context: we run these paths on a fork with XR whose low end is iPhone XS, Apple TV 4K 1st gen, and Meta Quest 1
Code path (master 020832ba; Babylon.js master 44afd643)
- JS calls
engine.updateDynamicVertexBuffer(...)with no commands staged, for example a thin-instance buffer update before any draw of the frame is encoded. NativeEngine::UpdateDynamicVertexBuffer(Plugins/NativeEngine/Source/NativeEngine.cpp) callsSubmitCommands(info).SubmitCommandscallsm_commandStream->GetReader();NativeDataStream::GetReader(Plugins/NativeEngine/Source/NativeDataStream.h) callsm_requestFlushCallback.Call({})(native -> JS).NativeDataStream._flush(packages/dev/core/src/Engines/Native/nativeDataStream.ts) callsthis._nativeDataStream.writeBuffer(this._uint32s.buffer, this._position)with_position === 0(JS -> native).NativeDataStream::WriteBufferappends nothing.reader.CanRead()is false andSubmitCommandsreturns.
When draws are staged the drain is required for ordering (#1871). This issue is about the empty case and about the callback hop itself.
Suggested direction
- Small, Babylon.js only: return early from
NativeDataStream._flushwhen_position === 0. That removes the innerwriteBuffercall with no protocol change. - Larger: let native read the staged length without calling into JavaScript, for example by sharing the staging buffer and its write position with
NativeDataStream, soGetReader()needs no callback for either empty or non-empty drains.
- 主要言語
- C++
- スター
- 931
- フォーク
- 169
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 66
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
BabylonJS/BabylonNative のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
BabylonJS/BabylonNative#2138 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
BabylonJS/BabylonNative#2042 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
BabylonJS/BabylonNative#2052 ·
メンテナーはふだん 1 日以内に返信
-
testing
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
BabylonJS/BabylonNative#2136 ·
メンテナーはふだん 1 日以内に返信
-
Support useNDCHalfZRange (half-range NDC depth) so Babylon.js half-range depth visual tests can runオープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
BabylonJS/BabylonNative#2134 ·
メンテナーはふだん 1 日以内に返信
BabylonJS/BabylonNative の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
simnJS/AnyPS5#735 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
needs-format
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Niko1221/Strata#7719 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
area:tests kind:test
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信