Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

swagger-validator performance improvement ideas #394

Open
winguse opened this issue Jun 11, 2016 · 7 comments
Open

swagger-validator performance improvement ideas #394

winguse opened this issue Jun 11, 2016 · 7 comments

Comments

@winguse
Copy link

winguse commented Jun 11, 2016

I did some performance diagnostic in swagger-tools, and I found that, for a request, the most time spending module in the API infrastructure is the validator middleware. By looking into the call stack, most of the time is spending in helpers.js#L59.

For this simple schema:

{
  "type": "object",
  "required": [ "email" ],
  "properties": {
    "email": {
      "type": "string"
    }
  }
}

It still takes about 1ms for it. (Comparing to the fact that all other stacks take 1ms.)

By looking into the doc of ZSchema, I cannot find any description about caching the complied schema.

Further, I also found that other projects doing similar jobs seem to have a better performance.

And Ajv is providing support for caching the compiled schema.

I am new to swagger-tools, so I don't know if there is some other considerations in choosing of ZSchema (If have, would you like to give some information here?). But for my research, if there is no special consideration, I think it's good to replace it by Avj, which may improve the performance.

Thanks!

@whitlockjc
Copy link
Member

Thanks a lot for your feedback. I'll make sure to use this for https://github.com/apigee-127/sway

@winguse
Copy link
Author

winguse commented Jun 12, 2016

By looking into project sway, is sway going to replace the validation logic inside swagger-tools in the future?

@whitlockjc
Copy link
Member

#335 explains what is going on. Read this and let me know if things are more clear.

@winguse
Copy link
Author

winguse commented Jun 12, 2016

glad to know, thanks for your hard-work!

@techana
Copy link

techana commented Jun 12, 2016

Seems good. Thank you. What's the status of Sway now? Can it be used for new API projects?

@whitlockjc
Copy link
Member

Sway is ready as an API but the middleware part (https://github.com/whitlockjc/sway-connect) is not yet complete. So if you use swagger-tools' API, Sway is a much better alternative. But if you use the swagger-tools middleware, the replacement is not complete yet.

@techana
Copy link

techana commented Jun 12, 2016

I'm using swagger-tools middleware. Will it be easy to switch to sway-connect when it's ready in the future?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants