-
-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Is there an existing issue or pull request for this?
- I have searched the existing issues and pull requests
Feature description
Right now, all validators have checks for whether or not they should run validations, as seen below:
shapeshift/src/validators/BaseValidator.ts
Lines 74 to 78 in e9a029a
| // If validation is disabled (at the validator or global level), we only run the `handle` method, which will do some basic checks | |
| // (like that the input is a string for a string validator) | |
| if (!this.shouldRunConstraints) { | |
| return this.handle(value).unwrap() as R; | |
| } |
This comes with a large performance impact, specially from those who desire to use the library without conditional validation. Also goes against Shapeshift's internal design of running the least amount of conditionals as possible.
Before we added conditional validation, Shapeshift was comfortably among the fastest libraries in our benchmarks.
Desired solution
A wrapper would solve the performance impact by making the validators always run the logic and constraints, where the PartialValidator<T> would exclusively only run the handler and never the constraints (with no extra checks, of course).
For function (dynamic validation), we can also add a second class, or add a check in PartialValidator<T>, invalidating the last sentence in the previous paragraph.
Unwrapping a PartialValidator<T> should give back the underlying, fully-checked validator.
Alternatives considered
N/a.
Additional context
No response