-
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
enhancementNew feature or requestNew feature or request
Description
What is the problem this feature would solve?
JS engine JSON.stringify
has become a lot faster.
I recently test mainstream validators and json-accelerator
with JSON.stringify
in both Node and Bun: https://github.com/re-utils/stnl/tree/dev/bench/all
json-accelerator
is the fastest among validators but still around 1.13x slower than JSON.stringify
(and 2x slower in Bun comparing to its non-recursive JSON.stringify
- enabled using env BUN_JSC_useRecursiveJSONParse=false
).
What is the feature you are proposing to solve the problem?
Here's the cases that may benefits from a JSON stringifier compiler:
const __number_list = (o: any[]) => {
let _ = '[';
for (let i = 0; i < o.length; i++) _ += (i === 0 ? '' : ',') + o[i];
return _ + ']';
};
const __bool_list = (o: any[]) => {
let _ = '[';
for (let i = 0; i < o.length; i++)
_ += (i === 0 ? '' : ',') + (o[i] ? 'true' : 'false');
return _ + ']';
};
const __number = (o: any) => '' + o;
const __bool = (o: boolean) => (o ? 'true' : 'false');
imo json-accelerator
should optimize only for these cases and fallback to JSON.stringify
in others.
What alternatives have you considered?
No response
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request