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

Aperta Adatta ai principianti
#3,405 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dchaudhari7177 ci sta già lavorando.

Dal 20/11/2026.

  • #3423 di @dchaudhari7177 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Inizia in compiledIO.ts, dove le scritture f16 chiamano DataView.setFloat16, e leggi numeric.ts per la conversione toHalfBits esistente. Verifica che l’output in byte del writer compilato corrisponda a quello del writer di fallback e a quello di setFloat16 nativo quando disponibile. Il lavoro è completato quando le scritture riescono senza setFloat16, producono gli stessi byte ed evitano l’avviso del writer di fallback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
3.4k
Fork
151
Merge medio
3g 8h
PR unite (30g)
55

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di software-mansion/TypeGPU

Tutte le issue di software-mansion/TypeGPU

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.