Support TypedArrays

オープン
#626 コメント 1 件 リアクション 4 件 担当者 0 名 GitHub で見る

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

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

2026年11月4日 から。

  • #913 @junaidkhan80121 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript

調査の方向性

まず、issue で示されている Array.isArray チェックの周辺にある index.js を読み、Float32Array の例を再現します。提案されているスキーマ互換性と largeArrayMechanism の動作がどのようになるべきかを確認します。互換性のあるスキーマに対して TypedArrays が正しくシリアライズされ、通常の配列の動作が変更されなければ完了です。

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

説明

feature request
Prerequisites
  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal

fast-json-stringify does not work with TypedArray objects (Float32Array, etc.). Normally, using JSON.stringify to serialize a TypedArray results in writing it as an object (e.g., new Float32Array([0.1,0.2]) gets serialized as {"0":0.1,"1":0.2}). However, since fast-json-stringify uses a JSON Schema to guide its output, it can know that a given property is an array; it seems reasonable and consistent to allow it to serialize TypedArrays as well as regular arrays.

Proposed implementation:

  • The Array.isArray check could be broadened to also allow TypedArrays.
  • TypedArray can only hold (floating point or integer) numbers, so it would not work with many JSON Schemas. One option would be to only allow TypedArray if the JSON Schema is compatible with TypedArray (e.g., only number items); another option would be to allow it as is and then let individual elements fail validation.
  • If a TypedArray is in use, largeArrayMechanism is ignored (treated as default).
Motivation

Our application uses TypedArray for several purposes. This is fast internally but is noticeably slower to serialize. Using fast-json-stringify, locally patched to support TypedArray, is over 2.5x faster for a Float32Array of 4000 randomly generated numbers.

Example
const array = new Float32Array(new Array(4000).fill(1));

const stringify = fastJson({
  title: 'Example Schema',
  type: 'array',
  items: {
    type: 'number'
  }
})

console.log(stringify(array));
主要言語
JavaScript
スター
3.7k
フォーク
245
平均マージ
3日 5時間
マージ済み PR(30日)
16

環境構築

はじめの一歩

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

fastify/fast-json-stringify のほかの issue

fastify/fast-json-stringify の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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