Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue #176

Closed
Eli-Black-Work opened this issue May 18, 2020 · 5 comments · Fixed by #195
Closed

Performance issue #176

Eli-Black-Work opened this issue May 18, 2020 · 5 comments · Fixed by #195

Comments

@Eli-Black-Work
Copy link

First of all, thanks for writing this library :)

We're running into a performance issue that I wanted to alert you to.

We're loading a fairly large (~900KB) JSON schema file, parsing it, and running the resulting JavaScript object through this library's dereference() function. The dereference() call takes around 68 seconds to complete.

We've disabled all loading of local or external files, so I don't think that any of the time spent in dereference() is due to loading external resources.

Here's basically what the code looks like:

const rawSchema = fetch(...);
const schema = JSON.parse(rawSchema);

if (typeof (schema) !== 'object')
	throw `The schema was not an object.`;

const options = {
	parse: {
		json: false,
		yaml: false,
		text: false,
		binary: false
	},
	resolve: {
		external: false,
		file: false,
		http: false
	},
	continueOnError: false,
	dereference: {
		circular: true
	}
};

console.log(performance.now());

$SchemaRefParser
	.dereference(schema, options)
	.then(dereferencedSchema => {
		console.log(performance.now());
	});

The schema does contain circular references.

@tahpot
Copy link

tahpot commented May 19, 2020

I have similar issues with a 4MB json schema file (FHIR).

@paztis
Copy link
Contributor

paztis commented Oct 2, 2020

any updates for this defect ?
I'm also facing it

@paztis
Copy link
Contributor

paztis commented Oct 20, 2020

I encounter this performance problem in case of non direct circular reference

In this simple case, I enter 680 times in the dereference$Ref function

"interface-.ts-69348-69886-.ts-0-209362": {
      "type": "object",
      "properties": {
        "byteLength": {
          "type": "number"
        },
        "slice": {
          "type": "function",
          "arguments": {
            "begin": {
              "type": "number"
            },
            "end": {
              "type": "number"
            }
          },
          "return": {
            "$ref": "#/definitions/interface-.ts-69348-69886-.ts-0-209362"
          },
          "required": [
            "begin"
          ]
        }
      },
      "required": [
        "byteLength",
        "slice"
      ],
      "additionalProperties": false
    },

Can you take a look at this problem ? this is really annoying

@paztis
Copy link
Contributor

paztis commented Oct 20, 2020

Sorry bad example, I didn't pass so much time inside this one.
Try to find a better example

@paztis
Copy link
Contributor

paztis commented Oct 20, 2020

found a fix
It's available in my PR: #195
Now performances are really good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants