Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache pre-compiled AJV validators #1590

Closed
2 tasks
bajtos opened this issue Aug 2, 2018 · 0 comments
Closed
2 tasks

Cache pre-compiled AJV validators #1590

bajtos opened this issue Aug 2, 2018 · 0 comments
Assignees
Labels
REST Issues related to @loopback/rest package and REST transport in general Validation

Comments

@bajtos
Copy link
Member

bajtos commented Aug 2, 2018

The initial implementation of request-body validation uses the more convenient but significantly less-performant API from AJV:

https://github.com/strongloop/loopback-next/blob/34eba3498528fe70fa9e64e8582d30a5b255e35b/packages/rest/src/validation/request-body.validator.ts#L93-L103

As a result, a typical POST (create) request is 10x slower than a GET (find) request.

We should rework our validation to cache pre-compiled AJV validators, see docs.

  • To avoid slow application start, validators should be precompiled lazily (on the first request).
  • Precompiled validators can be stored for example as a new property of the RouteEntry class.

Acceptance criteria

  • Modify request-body validator to cache pre-compiled validators
  • Re-run our benchmark and update its README with the newly observed data
@bajtos bajtos added LB4 GA Validation REST Issues related to @loopback/rest package and REST transport in general labels Aug 2, 2018
@bajtos bajtos added the p1 label Aug 13, 2018
@virkt25 virkt25 added stretch and removed stretch labels Sep 4, 2018
@hacksparrow hacksparrow self-assigned this Sep 24, 2018
@bajtos bajtos added this to the October Milestone milestone Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REST Issues related to @loopback/rest package and REST transport in general Validation
Projects
None yet
Development

No branches or pull requests

3 participants