natesilva / jayschema

[Unmaintained] - A comprehensive JSON Schema validator for Node.js
BSD 3-Clause "New" or "Revised" License
217 stars 22 forks source link

Caches validator functions in hot path #51

Closed markyen closed 9 years ago

markyen commented 9 years ago

A lot of validation time is being spent in require. Though there is a require cache for the actual loading of the required file, the pathname still needs to be resolved and validated when requiring a relative path.

Caching the validator functions immediately gave me a 5-6x speedup on a small micro-benchmark I put together, but it will easily give bigger speedups with more complex objects.

before x 288 ops/sec ±2.35% (83 runs sampled)
after x 1,609 ops/sec ±2.30% (88 runs sampled)
natesilva commented 9 years ago

Wow, thank you. All tests pass.