-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fast-json-stringify slow on STR_ESCAPE regex #1005
Comments
Not at this time. However a way to do so could be a great addition to the library. |
mhh yep, I think is a big booster... Maybe the "format" in the JSON Schema? "name": {
"type": "string",
"format": "unescape"
} and asString (str, format) {
if (typeof str !== 'string') {
if (str === null) {
return '""'
}
if (str instanceof Date) {
return '"' + str.toISOString() + '"'
}
if (str instanceof RegExp) {
str = str.source
} else {
str = str.toString()
}
}
if( format === "unescape"){
return '"' + str + '"'
} else if (str.length < 42) {
return this.asStringSmall(str)
} else if (STR_ESCAPE.test(str) === false) {
return '"' + str + '"'
} else {
return JSON.stringify(str)
}
} |
unescape has already a specific meaning. Lol, it is even a function in javascript So unescape is not considerable. |
Side note, why |
Up to 42. Why 42? Idk |
I though it is just a random picked number for small string. |
+1 for |
I have made a PR fastify/fast-json-stringify#685 benchmark (compare classic bench VS same bench with format raw)
raw string seem x45 faster |
I have a JSON with a lot of strings that take time during the STR_ESCAPE regex evaluation. Some of these strings I know are safe (no need to escape), is there a way to skip regex evaluation in some way?
The text was updated successfully, but these errors were encountered: