Speed up validator build by avoiding is_file()#23
Conversation
osteel
left a comment
There was a problem hiding this comment.
Hey Paul! Thank you for your pull request. I understand where you come from with this and any performance gain is nice, although in this case I'd say it's fairly small, all things considered. Does it make a huge difference in your specific use case?
The "issue" I've got with this at the moment is that if we introduce public methods to load string definitions directly, I feel like there should also be methods to load files straight away.
So I'd add fromJsonFile and fromYamlFile as well.
More coherent this way I think, and we'd still not be introducing any breaking changes.
What do you think?
This would also imply restructuring the README a little bit, but you can leave that to me (I already wanted to introduce some cosmetic changes anyway, so could do that at the same time)
|
Thank you! |
Description
Adds
fromYamlRaw()andfromJsonRaw()methods toValidatorBuilderInterface.Motivation and context
Our project required testing output of hundreds of permutations of API requests. We noticed that our tests seemed rather slow, so we did some digging and found that
ValidatorBuildercallsis_file()for all builds.Adding a
fromYamlRaw()method will allow us to bypass this call and improve performance.If it fixes an open issue, please link to the issue here (if you write
fixes #numor
closes #num, the issue will be automatically closed when the pull is accepted.)How has this been tested?
Firstly the PR adds test cases to
ValidatorBuilderTestto cover the new lines of code.Secondly, this PR adds a test called
ValidatorBuilderSpeedTest. All it does is build a validator using whichever method is uncommented. It's not a super-great test. :-)We also add a Composer script that runs this test 10,000 times.
Comparison results look like this:
Using
fromYaml()andfromJson():Using
fromYamlRaw()andfromJsonRaw():Screenshots (if appropriate)
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:Checklist:
Go over all the following points, and put an
xin all the boxes that apply.Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our continuous integration server to make sure your tests and code style pass.
If you're unsure about any of these, don't hesitate to ask. We're here to help!