arb / celebrate

A joi validation middleware for Express.
MIT License
1.33k stars 66 forks source link

New Internals #168

Closed arb closed 4 years ago

arb commented 4 years ago

After staring at the main validation path for a few hours, I realized a lot of this code is more complex than it really needed to be.

Biggest changes:

Benchmarks

These values come from node utils/benchmark:

pre-change

valid x 32,945 ops/sec ±5.60% (77 runs sampled) invalid x 23,976 ops/sec ±1.96% (85 runs sampled)

valid x 37,814 ops/sec ±1.73% (80 runs sampled) invalid x 24,608 ops/sec ±2.28% (85 runs sampled)

valid x 31,047 ops/sec ±8.14% (78 runs sampled) invalid x 24,413 ops/sec ±2.22% (82 runs sampled)

after-change

valid x 350,009 ops/sec ±1.76% (73 runs sampled) invalid x 337,577 ops/sec ±4.04% (72 runs sampled)

valid x 343,469 ops/sec ±5.65% (27 runs sampled) invalid x 205,444 ops/sec ±4.48% (26 runs sampled)

valid x 385,833 ops/sec ±2.49% (53 runs sampled) invalid x 353,932 ops/sec ±6.53% (72 runs sampled)

Unless I'm doing something incredibly wrong, that's an order of magnitude faster 😮

codecov-io commented 4 years ago

Codecov Report

Merging #168 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #168   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines          64     62    -2     
  Branches       12     11    -1     
=====================================
- Hits           64     62    -2
Impacted Files Coverage Δ
lib/index.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b423571...f651615. Read the comment docs.