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

Abierto Apto para principiantes
#3,405 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@dchaudhari7177 ya está trabajando en esto.

Desde el 20/11/2026.

  • #3423 de @dchaudhari7177 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Empieza en compiledIO.ts, donde las escrituras de f16 llaman a DataView.setFloat16, y lee numeric.ts para ver la conversión existente toHalfBits. Comprueba que la salida de bytes del escritor compilado coincide con la del escritor de reserva y con setFloat16 nativo cuando esté disponible. Se considera terminado cuando las escrituras se realizan correctamente sin setFloat16, producen los mismos bytes y evitan la advertencia del escritor de reserva.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
3.4k
Forks
151
Merge medio
3 d 8 h
PR fusionados (30 d)
55

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de software-mansion/TypeGPU

Todos los issues de software-mansion/TypeGPU

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.