Support TypedArrays
维护者通常 2 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
调研方向
首先阅读 issue 中提到的 Array.isArray 检查附近的 index.js,并复现 Float32Array 示例。检查提议的 schema 兼容性和 largeArrayMechanism 行为应如何工作;当 TypedArrays 能够针对兼容的 schema 正确序列化,且不改变普通数组的行为时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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 小时
- 30 天内合并 PR
- 16
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fastify/fast-json-stringify 的其他 Issue
-
benchmark question
难度 5/5 一周以上 新手友好度 20/100
fastify/fast-json-stringify#782 · 15 条评论 ·
维护者通常 2 天内回复
-
allOf Fails to Handle Array of if/then as Chained else Conditions可能已有人在做 @junaidkhan80121 于 18 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 35/100
fastify/fast-json-stringify#778 · 5 条评论 ·
维护者通常 2 天内回复
-
When `asString` receives `undefined` an exception is thrown可能已有人在做 @cpruijsen 于 47 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 35/100
fastify/fast-json-stringify#680 · 2 条评论 ·
维护者通常 2 天内回复
-
emit CJS/ESM syntax in standalone mode based on AJV code options可能已有人在做 @jaideeppyne 于 101 天前认领。 未关闭feature request
难度 4/5 3-5 天 新手友好度 42/100
fastify/fast-json-stringify#679 · 1 条评论 ·
维护者通常 2 天内回复
-
feature request
难度 5/5 一周以上 新手友好度 25/100
fastify/fast-json-stringify#627 · 4 条评论 · 3 个 reaction ·
维护者通常 2 天内回复
查看 fastify/fast-json-stringify 的全部 Issue
相似的 Issue
-
FEATURE REQUEST
难度 2/5 1-3 小时 新手友好度 67/100
linuxmint/cinnamon-spices-applets#9356 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
needs-triage Platform(Default)
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
维护者通常 1 天内回复