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

オープン 初心者向け
#3,405 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@dchaudhari7177 がすでに取り組んでいます。

2026年11月20日 から。

  • #3423 @dchaudhari7177 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

f16の書き込みがDataView.setFloat16を呼び出すcompiledIO.tsから始め、既存のtoHalfBits変換についてnumeric.tsを確認してください。コンパイル済みwriterのバイト出力を、fallback writerおよび利用可能な場合はネイティブのsetFloat16と比較してください。setFloat16なしで書き込みが成功し、一致するバイトを生成し、fallbackの警告を回避できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
3.4k
フォーク
151
平均マージ
3日 8時間
マージ済み PR(30日)
55

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/TypeGPU のほかの issue

software-mansion/TypeGPU の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。