Skip to content

Use json schemer gem for all schemas

Can Eldem requested to merge change-json-validation into master

What does this MR do?

This MR uses json schemer gem instead of using two gems to validate json schemas. Json schemer is also significantly faster. Here there is a micro benchmark that you can run on your computer.

begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end
gemfile(false) do
  source 'https://rubygems.org'
  gem 'benchmark-ips'
  gem 'json-schema'
  gem 'json_schemer'
end
SCHEMA_PATH = 'perf/data/test_schema.json'
PATH_NAME = Pathname.new(SCHEMA_PATH)
DATA = {}.freeze
validator = JSONSchemer.schema(PATH_NAME)
Benchmark.ips do |b|
  b.report('JSON::Validator') do
    JSON::Validator.validate(SCHEMA_PATH, DATA)
  end
  b.report('JSONSchemer') do
    JSONSchemer.schema(PATH_NAME).valid?(DATA)
  end
  b.report('JSONSchemer instance') do
    validator.valid?(DATA)
  end
  b.compare!
end

Results

~ » ruby benchmark.rb
Warming up --------------------------------------
     JSON::Validator   155.000  i/100ms
         JSONSchemer   454.000  i/100ms
JSONSchemer instance     2.587k i/100ms
Calculating -------------------------------------
     JSON::Validator      1.526k (± 3.5%) i/s -      7.750k
         JSONSchemer      4.985k (± 7.1%) i/s -     24.970k
JSONSchemer instance     31.353k (± 6.4%) i/s -    157.807k

Comparison:
JSONSchemer instance:    31353.4 i/s
         JSONSchemer:     4984.8 i/s - 6.29x slower
     JSON::Validator:     1526.2 i/s - 20.54x slower
Edited by Can Eldem

Merge request reports

Loading