Faster-Schema - limited, but faster simple-schema alternative

I just wrote the Faster-Schema package (on npm) which offers an API that’s very similar to Simple-Schema while being much faster, but with the main difference that it doesn’t support mongo modifiers and therefore has no Collection2 integration. It also has no Tracker integration although that wouldn’t be hard to add.

Rationale:
Our application depends heavily on the cleaning and validating of data objects by Simple-Schema. Simple-Schema provides an API we like with a lot of flexibility. However, some of our data objects have grown very large with very complex combined schemas and we found Simple-Schema taking up multiple seconds of CPU time to clean and validate these objects. Blocking the event loop synchronously for that amount of time is something you never should do in an event-loop system like Nodejs.

Unfortunately because Simple-Schema has to support mongo modifiers it has a lot of complexity that makes it slow. Since we didn’t really use this functionality in our application I set out to write another package without support for this.

For this complex example: https://github.com/sebakerckhof/schema-comparison , the performance difference is about 80x faster cleaning (1600ms vs 20ms) and 20x faster validation (700ms vs 30ms).

A complete comparison stating the API differences and the features we do not support can be found here

If you have small schemas and small objects, you probably shouldn’t bother and stick with SimpleSchema, but this might save some people that run into the same performance problems.

9 Likes