Skip to content

Commit e21f568

Browse files
committed
Add modernjsonschemavalidator
1 parent 408b908 commit e21f568

File tree

9 files changed

+134
-0
lines changed

9 files changed

+134
-0
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ jobs:
4343
path: dist/report.csv
4444
key: ${{ matrix.impl }}-${{ hashFiles(format('implementations/{0}/**/*', matrix.impl), 'schemas/**/*', 'report.sh') }}-${{ inputs.runs || 3 }}
4545

46+
- uses: oven-sh/setup-bun@v2
47+
with:
48+
bun-version: latest
49+
4650
- name: Run benchmarks
4751
if: steps.cache-report.outputs.cache-hit != 'true'
4852
continue-on-error: true
@@ -75,6 +79,7 @@ jobs:
7579
report-json_schemer: ${{ steps.save-output.outputs.report-json_schemer }}
7680
report-jsoncons: ${{ steps.save-output.outputs.report-jsoncons }}
7781
report-jsonschemadotnet: ${{ steps.save-output.outputs.report-jsonschemadotnet }}
82+
report-mjs: ${{ steps.save-output.outputs.report-mjs }}
7883
report-kmp-json-schema-validator: ${{ steps.save-output.outputs.report-kmp-json-schema-validator }}
7984
report-python-jsonschema: ${{ steps.save-output.outputs.report-python-jsonschema }}
8085
report-schemasafe: ${{ steps.save-output.outputs.report-schemasafe }}
@@ -93,6 +98,7 @@ jobs:
9398
- uses: actions/setup-python@v5
9499
with:
95100
python-version: '3.12.5'
101+
96102
- name: Install uv
97103
run: pipx install uv
98104

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/dist
22
/implementations/ajv/node_modules
33
/implementations/boon/target/
4+
/schemas/*/schema-2020-12.json
45
/.DS_Store
56
/node_modules
67
.dockertimestamp

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ define docker_run
4141
done
4242
endef
4343

44+
schemas/%/schema-2020-12.json: \
45+
schemas/%/schema.json
46+
bunx alterschema --from draft4 --to 2020-12 $< > $@
47+
48+
.PRECIOUS: schemas/%/schema-2020-12.json
49+
4450
# Blaze
4551

4652
implementations/blaze/.dockertimestamp: \
@@ -244,3 +250,21 @@ dist/results/kmp-json-schema-validator/%: \
244250
schemas/%/instances.jsonl \
245251
| dist/results/kmp-json-schema-validator
246252
@$(call docker_run,kmp-json-schema-validator,/workspace/$(word 2,$^) /workspace/$(word 3,$^))
253+
254+
# MJS
255+
256+
implementations/mjs/.dockertimestamp: \
257+
implementations/mjs/build.sbt \
258+
implementations/mjs/Benchmark.scala \
259+
implementations/mjs/project/build.properties \
260+
implementations/mjs/project/plugins.sbt \
261+
implementations/mjs/Dockerfile
262+
docker build -t jsonschema-benchmark/mjs implementations/mjs
263+
touch $@
264+
265+
dist/results/mjs/%: \
266+
implementations/mjs/.dockertimestamp \
267+
schemas/%/schema-2020-12.json \
268+
schemas/%/instances.jsonl \
269+
| dist/results/mjs
270+
@$(call docker_run,mjs,/workspace/$(word 2,$^) /workspace/$(word 3,$^))

implementations/mjs/Benchmark.scala

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import main.MainClass
2+
3+
import scala.io.Source
4+
5+
object Benchmark {
6+
val WARMUP_ITERATIONS = 1000
7+
val MAX_WARMUP_TIME = 1e9 * 10
8+
9+
def validateAll(schema: String, instance: String, registryMap: Map[String, String], instances: List[String]): Boolean = {
10+
var result = true
11+
for (instance <- instances) {
12+
result = result && MainClass.validateInstance(schema, instance, registryMap)
13+
}
14+
return result
15+
}
16+
17+
def main(args: Array[String]): Unit = {
18+
if (args.length != 2) {
19+
System.exit(1)
20+
}
21+
val schemaPath = args(0)
22+
val instancePath = args(1)
23+
24+
val compileStart = System.nanoTime()
25+
val schema = Source.fromFile(schemaPath).mkString
26+
val registryMap = Map.empty[String, String]
27+
val compileEnd = System.nanoTime()
28+
29+
val instances = Source.fromFile(instancePath).getLines().toList
30+
31+
val coldStart = System.nanoTime()
32+
var result = validateAll(schema, instancePath, registryMap, instances)
33+
val coldEnd = System.nanoTime()
34+
35+
if (!result) {
36+
System.err.println("Invalid instance")
37+
System.exit(1)
38+
}
39+
40+
val iterations = (MAX_WARMUP_TIME / (coldEnd - coldStart)).ceil.toInt
41+
(1 to iterations.min(WARMUP_ITERATIONS)).foreach(_ => {
42+
validateAll(schema, instancePath, registryMap, instances)
43+
})
44+
45+
val warmStart = System.nanoTime()
46+
validateAll(schema, instancePath, registryMap, instances)
47+
val warmEnd = System.nanoTime()
48+
49+
println((coldEnd - coldStart).toString + "," + (compileEnd - compileStart).toString)
50+
}
51+
}

implementations/mjs/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM sbtscala/scala-sbt:eclipse-temurin-17.0.4_1.7.2_2.13.10 AS builder
2+
3+
WORKDIR /app
4+
5+
# Build the project to cache the dependencies
6+
COPY build.sbt /app
7+
COPY project /app/project
8+
RUN sbt assembly
9+
10+
# Add the app and build again
11+
COPY Benchmark.scala /app
12+
RUN sbt assembly
13+
14+
ENTRYPOINT ["java", "-jar", "/app/target/scala-2.13/benchmarkMjs.jar"]
15+
CMD []

implementations/mjs/build.sbt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name := "mjs-validator"
2+
3+
ThisBuild / version := "1.0"
4+
ThisBuild / scalaVersion := "2.13.10"
5+
6+
javacOptions ++= Seq("-source", "17", "-target", "17")
7+
8+
resolvers += Resolver.mavenCentral
9+
10+
libraryDependencies ++= Seq(
11+
"org.scala-lang" % "scala-library" % "2.13.10"
12+
)
13+
14+
val mjsVersion = "v0.1.0"
15+
lazy val mjs = RootProject(
16+
uri(s"https://gitlab.lip6.fr/jsonschema/modernjsonschemavalidator.git#$mjsVersion")
17+
)
18+
lazy val benchmarkMjs = (project in file(".")).dependsOn(mjs)
19+
assembly / assemblyJarName := "benchmarkMjs.jar"
20+
assembly / packageOptions := Seq(
21+
Package.ManifestAttributes(
22+
"Main-Class" -> "Benchmark",
23+
"Implementation-Group" -> "org.up.mjs",
24+
"Implementation-Name" -> "mjs",
25+
"Implementation-Version" -> mjsVersion
26+
)
27+
)
28+
29+
scalacOptions += "-Ymacro-annotations"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.9.6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.5")

implementations/mjs/version.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
grep '^val mjsVersion =' implementations/mjs/build.sbt | cut -d= -f2 | tr -d '" '

0 commit comments

Comments
 (0)