bug: f16 writes always fail in the compiled writer on engines without DataView.setFloat16 (React Native / Hermes)

Đang mở Phù hợp với người mới
#3,405 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@dchaudhari7177 đang làm issue này rồi.

Từ ngày 20/11/2026.

  • #3423 của @dchaudhari7177 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/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ệ
typescript
Lĩnh vực
backend, performance

Hướng nghiên cứu

Bắt đầu trong compiledIO.ts, nơi các lệnh ghi f16 gọi DataView.setFloat16, và đọc numeric.ts để xem phép chuyển đổi toHalfBits hiện có. Kiểm tra đầu ra byte của writer đã biên dịch so với writer dự phòng và setFloat16 gốc khi có sẵn. Hoàn thành khi các lần ghi thành công mà không cần setFloat16, tạo ra các byte khớp nhau và tránh cảnh báo dự phòng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

On engines without DataView.prototype.setFloat16 (Hermes in React Native; also Node 22 and older browsers), every write of data that contains f16 throws inside the compiled writer. TypeGPU then falls back to the slow writer and logs a "this is likely a bug" warning on every call.

Repro

Node 24, with setFloat16 removed to mimic Hermes:

import { d } from 'typegpu';
import { writeToArrayBuffer } from './src/data/dataIO.ts';

delete (DataView.prototype as any).setFloat16;

const schema = d.arrayOf(d.f16, 100_000);
const data = Array.from({ length: 100_000 }, (_, i) => i * 0.001);
writeToArrayBuffer(new ArrayBuffer(d.sizeOf(schema)), schema, data);

Output, repeated on every write:

⚠️ [fallback] Error when using compiled writer for data type 'array' (unnamed) - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues
Using fallback writer instead. TypeError: output.setFloat16 is not a function

Impact

  • Node 24, arrayOf(f16, 100k): ~0.12 ms with native setFloat16 vs ~1.75 ms without it, plus one warning per write.
  • iPhone (react-native-webgpu 0.22, Hermes), mnist-inference example: uploading the weights takes 320 ms; with the fix below it takes 155 ms.
  • #3383 adds mat*h schemas that go through the same setFloat16 path, so they would be affected too.

Cause

compiledIO.ts maps f16 to setFloat16 without checking that the method exists. The writer is built fine and throws only at write time, so the failure repeats on every call.

Possible fix

Feature-detect once. When setFloat16 is missing, emit:

output.setUint16(offset, toHalfBits(v), littleEndian);

toHalfBits already exists in numeric.ts. Optionally, add a one-loop fast path for arrayOf(f16).

I have a local version with tests (bytes match both the fallback writer and native setFloat16) if that helps.

Ngôn ngữ chính
TypeScript
Star
3.4k
Fork
151
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
55

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của software-mansion/TypeGPU

Tất cả issue của software-mansion/TypeGPU

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.