flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.13k stars 91 forks source link

More performant check of isPlainObject #204

Closed tomhooijenga closed 2 years ago

tomhooijenga commented 2 years ago

Before:

toy example x 89,736 ops/sec ±0.91% (97 runs sampled)
user graph x 21,863 ops/sec ±0.37% (90 runs sampled)
deep nested x 21.42 ops/sec ±1.54% (40 runs sampled)

After:

toy example x 94,658 ops/sec ±1.14% (92 runs sampled)
user graph x 23,187 ops/sec ±0.38% (96 runs sampled)
deep nested x 22.04 ops/sec ±1.26% (41 runs sampled)

Also, isPlainObject would return true on Object.prototype which is now fixed and added to the tests.