refactor: use built-in wellformed operation
From my local benchmark, it vary too large to conclude it has improvement or regression.
Checklist
- [ ] run
npm run testandnpm run benchmark - [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message and code follows the Developer's Certification of Origin and the Code of conduct
PR:
short string............................................. x 24,298,246 ops/sec ±0.31% (193 runs sampled)
unsafe short string...................................... x 837,305,509 ops/sec ±0.10% (194 runs sampled)
short string with double quote........................... x 12,935,483 ops/sec ±0.98% (189 runs sampled)
long string without double quotes........................ x 10,421 ops/sec ±0.17% (193 runs sampled)
unsafe long string without double quotes................. x 836,880,191 ops/sec ±0.11% (194 runs sampled)
long string.............................................. x 10,378 ops/sec ±0.15% (194 runs sampled)
unsafe long string....................................... x 836,456,843 ops/sec ±0.12% (194 runs sampled)
number................................................... x 836,492,307 ops/sec ±0.07% (195 runs sampled)
integer.................................................. x 169,628,786 ops/sec ±0.07% (194 runs sampled)
formatted date-time...................................... x 1,917,810 ops/sec ±0.18% (192 runs sampled)
formatted date........................................... x 1,536,685 ops/sec ±0.27% (193 runs sampled)
formatted time........................................... x 1,536,111 ops/sec ±0.25% (190 runs sampled)
short array of numbers................................... x 78,345 ops/sec ±0.25% (193 runs sampled)
short array of integers.................................. x 74,924 ops/sec ±0.31% (193 runs sampled)
short array of short strings............................. x 19,646 ops/sec ±0.21% (192 runs sampled)
short array of long strings.............................. x 19,671 ops/sec ±0.27% (193 runs sampled)
short array of objects with properties of different types x 10,223 ops/sec ±0.29% (192 runs sampled)
object with number property.............................. x 832,014,686 ops/sec ±0.13% (194 runs sampled)
object with integer property............................. x 169,190,795 ops/sec ±0.09% (194 runs sampled)
object with short string property........................ x 24,424,523 ops/sec ±0.46% (192 runs sampled)
object with long string property......................... x 10,365 ops/sec ±0.15% (193 runs sampled)
object with properties of different types................ x 2,175,246 ops/sec ±0.28% (192 runs sampled)
simple object............................................ x 10,963,761 ops/sec ±0.54% (191 runs sampled)
simple object with required fields....................... x 10,733,221 ops/sec ±0.36% (191 runs sampled)
object with const string property........................ x 834,126,400 ops/sec ±0.09% (195 runs sampled)
object with const number property........................ x 835,264,759 ops/sec ±0.09% (193 runs sampled)
object with const bool property.......................... x 838,081,231 ops/sec ±0.10% (194 runs sampled)
object with const object property........................ x 838,001,357 ops/sec ±0.12% (193 runs sampled)
object with const null property.......................... x 838,954,956 ops/sec ±0.08% (194 runs sampled)
MAIN:
short string............................................. x 24,453,554 ops/sec ±0.58% (193 runs sampled)
unsafe short string...................................... x 834,223,077 ops/sec ±0.12% (195 runs sampled)
short string with double quote........................... x 13,074,151 ops/sec ±0.92% (188 runs sampled)
long string without double quotes........................ x 10,490 ops/sec ±0.15% (194 runs sampled)
unsafe long string without double quotes................. x 836,885,150 ops/sec ±0.13% (194 runs sampled)
long string.............................................. x 10,363 ops/sec ±0.17% (194 runs sampled)
unsafe long string....................................... x 839,876,570 ops/sec ±0.09% (193 runs sampled)
number................................................... x 836,385,915 ops/sec ±0.06% (195 runs sampled)
integer.................................................. x 169,932,358 ops/sec ±0.08% (194 runs sampled)
formatted date-time...................................... x 1,917,515 ops/sec ±0.22% (192 runs sampled)
formatted date........................................... x 1,539,718 ops/sec ±0.23% (192 runs sampled)
formatted time........................................... x 1,538,569 ops/sec ±0.28% (192 runs sampled)
short array of numbers................................... x 77,874 ops/sec ±0.23% (194 runs sampled)
short array of integers.................................. x 74,919 ops/sec ±0.24% (194 runs sampled)
short array of short strings............................. x 19,627 ops/sec ±0.23% (194 runs sampled)
short array of long strings.............................. x 19,567 ops/sec ±0.40% (194 runs sampled)
short array of objects with properties of different types x 10,147 ops/sec ±0.24% (192 runs sampled)
object with number property.............................. x 830,546,603 ops/sec ±0.11% (193 runs sampled)
object with integer property............................. x 169,635,710 ops/sec ±0.08% (195 runs sampled)
object with short string property........................ x 24,616,175 ops/sec ±0.20% (194 runs sampled)
object with long string property......................... x 10,394 ops/sec ±0.16% (193 runs sampled)
object with properties of different types................ x 2,178,729 ops/sec ±0.36% (192 runs sampled)
simple object............................................ x 10,309,481 ops/sec ±0.38% (193 runs sampled)
simple object with required fields....................... x 11,269,934 ops/sec ±0.30% (192 runs sampled)
object with const string property........................ x 840,400,406 ops/sec ±0.13% (194 runs sampled)
object with const number property........................ x 838,258,961 ops/sec ±0.04% (194 runs sampled)
object with const bool property.......................... x 842,191,670 ops/sec ±0.13% (194 runs sampled)
object with const object property........................ x 839,387,882 ops/sec ±0.11% (195 runs sampled)
object with const null property.......................... x 840,437,812 ops/sec ±0.10% (194 runs sampled)
The benchmark shows there is a regression on non-affected code routine. For my local environment, it show the similar conclusion but improvement on the string.
Can anyone confirm the same result on node@24? (Github Actions using node@22)
@KhafraDev fyi
isWellFormed() seem 2X faster, see bench
It should probably also be checked whether the magic numbers 42 and 5000 are still valid string lengths
@cesco69 If you want you can benchmark and provide maybe a PR ;)