-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The call to validate a schema is quite expensive: ``` [3] pry(#<GovukSchemas::RandomExample>)> puts Benchmark.measure { 100.times { JSON::Validator.fully_validate(@Schema, item, errors_as_objects: true) } } 7.614167 1.532485 9.146652 ( 10.468765) ``` This updates the code to avoid making two calls to the validator when a payload is generated with a block if the customised version is valid. Before: ``` irb(main):010:0> puts Benchmark.measure { 100.times { GovukSchemas::RandomExample.for_schema(frontend_schema: "news_artic le") { |schema| schema["title"] = "Custom"; schema } } } 13.308641 3.087679 16.396320 ( 18.977005) ``` After: ``` irb(main):002:0> puts Benchmark.measure { 100.times { GovukSchemas::RandomExample.for_schema(frontend_schema: "news_artic le") { |schema| schema["title"] = "Custom"; schema } } } 7.654303 1.561620 9.215923 ( 10.604802) ``` The motivation for this was that the GOV.UK Chat test suite makes quite heavy use of random schemas with customisations for checking supported schemas. On a MBP with GOV.UK Docker this reduces the time of the running the test suite from around ~55s to around ~35s.
- Loading branch information
Showing
3 changed files
with
60 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters