SPZs unusable on most devices because fetch/Blob/XMLHttpRequest copy the whole response body on every access; bodyUsed is never set
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- cpp, javascript, node.js
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
Start in Dependencies/JsRuntimeHost/Polyfills/Fetch/Source/Fetch.cpp, Blob.cpp, and XMLHttpRequest.cpp, following the body handling and copy sites linked in the issue. Read the Fetch and Blob implementations together, then check their existing tests before choosing a starting point. Done means response bodies and repeated XHR reads avoid the described full-payload copies, with bodyUsed and consumed-body behavior covered by regression tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Every way a script can read a response body makes a full copy of the whole payload, and nothing stops it from doing so repeatedly: fetch copies the transport buffer into its own vector, each body accessor copies again, blob() copies twice, and the XMLHttpRequest.response getter copies on every property read. bodyUsed is never set, so a consumed body is never transferred, only duplicated.
For the asset sizes 3D content now ships at, this is the difference between a scene loading and the process being killed. Gaussian splat scenes are 100–500 MB PLY files (or many LOD chunks of a streamed scene), SOG scenes are sets of large WebP/PNG textures, glTF/GLB and KTX2 containers run to hundreds of MB, and USDZ archives are larger still. On a 3–4 GB iPhone, two to four live copies of a 400 MB asset is jetsam territory; on every device, each copy is a full-bandwidth memcpy on the JS thread, which is CPU time and memory bandwidth taken from the frame.
Where the copies happen (BabylonNative master @ e79a4e3, Dependencies/JsRuntimeHost)
- Transport → Response. Completion copies UrlLib's buffer into
ResponseData::bodyinstead of taking ownership of it: Fetch.cpp#L499-L500. arrayBuffer()allocates a freshArrayBufferandmemcpys the whole body on every call: Fetch.cpp#L274-L277.blob()copies the body into anArrayBuffer(Fetch.cpp#L312-L317), then theBlobconstructor copies that into its own vector (Blob.cpp#L108-L120), andBlob.arrayBuffer()/bytes()copy once more on each call (Blob.cpp#L81-L84, #L94-L97).fetch(url).then(r => r.blob()).then(b => b.arrayBuffer())is four full copies of the payload: for a 300 MB asset, 1.2 GB ofmemcpyand up to four simultaneously live copies if the script keeps references.text()/json()build astd::stringcopy and then a JS string from it: Fetch.cpp#L263-L269, #L283-L287.XMLHttpRequest.responseis a getter that allocates and copies the whole buffer on every read: XMLHttpRequest.cpp#L120-L134. Browsers return the sameArrayBufferobject each time; here a loader that touchesrequest.responsetwice has copied the asset twice.bodyUsedis alwaysfalseby design (Fetch/Readme.md#L18), so there is no point at which the implementation may hand the buffer over rather than duplicate it.
Who hits it
Babylon.js loads almost everything through XMLHttpRequest with responseType = "arraybuffer" (webRequest.ts#L128): the Gaussian splat LOD streamer issues one such request per LOD file (gaussianSplattingDownloadManager.ts#L310), and SOG wraps the result in a Blob to decode it (sog.pure.ts#L463-L464). WebRequest.FetchAsync takes the fetch path whenever fetch exists (webRequest.ts#L121). Any glTF, KTX2 or USD pipeline built on these primitives pays the same multiples.
Proposed shape
- One immutable, reference-counted backing per response (
std::shared_ptr<const std::vector<std::byte>>, or UrlLib's buffer moved rather than copied) shared by theResponse, its clones, and anyBlobmade from it. arrayBuffer()/bytes()hand that backing to JS as an externalArrayBuffer(Napi::ArrayBuffer::New(env, data, length, finalizer)) that holds a reference: zero copies. Where an adapter cannot host external ArrayBuffers, one copy, cached and returned by identity thereafter.blob()constructs theBlobover the same backing;Blobparts built from other Blobs share rather than copy (Blobs are immutable, so this is spec-safe).XMLHttpRequest.responsematerializes itsArrayBufferonce per response and returns the same object on later reads, as the spec requires.- Implement
bodyUsed: a consumed body is transferred, and a second read rejects withTypeErroras in browsers, instead of silently copying.
A regression test can fetch an N-byte body, read it through each accessor, and assert peak allocation stays within N plus a small constant, alongside the functional bodyUsed checks.
Checked the tracker first: #1825 (SPZ loader, ReadableStream undefined), #1241 and #538 do not cover this; JsRuntimeHost#98 (Implement fetch API) and JsRuntimeHost#213 (blob: URL resolution) predate it.
- Ngôn ngữ chính
- C++
- Star
- 931
- Fork
- 169
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 66
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của BabylonJS/BabylonNative
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
BabylonJS/BabylonNative#2138 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BabylonJS/BabylonNative#2042 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
BabylonJS/BabylonNative#2052 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
testing
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
BabylonJS/BabylonNative#2136 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support useNDCHalfZRange (half-range NDC depth) so Babylon.js half-range depth visual tests can runĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
BabylonJS/BabylonNative#2134 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của BabylonJS/BabylonNative
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
gofractally/psibase#2379 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
simnJS/AnyPS5#735 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-format
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Niko1221/Strata#7719 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày