Skip to content

Performance degrades when an if-else check is applied on a huge map #54

@Navgeet

Description

@Navgeet

Consider this schema and these two payloads:
test.schema.json

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "string"
    }
  },
  "if": {
    "properties": {
      "foo": {
        "const": "foo"
      }
    }
  },
  "then": {
    "properties": {
      "bar": {
        "const": "bar"
      }
    }
  }
}

test.json

{
  "foo": "foo",
  "bar": "bar"
}

test-big.json

{
  "foo": "foo",
  "bar": "bar",
  "foo1": "foo",
  "foo2": "foo",
...
  "foo99": "foo",
  "foo100": "foo"
}

Running justify over these payloads (code.zip) 1M times yields these results:

test.json: 14835 ms
test-big.json: 55362 ms

Now this could be due to parsing cost of bigger map, so let's remove the if-then keywords and try again.

test.json: 13994 ms
test-big.json: 38727ms

Hence it is clear that something else is going on.
After running the code through debugger, I believe this is because ConditionalEvaluator's evaluate method is called for every key in the payload. Is this something that can be optimized?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions