Skip to content

performance: expand contexts in parseInnerContexts #74

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

Open
jeswr opened this issue Nov 20, 2023 · 1 comment
Open

performance: expand contexts in parseInnerContexts #74

jeswr opened this issue Nov 20, 2023 · 1 comment

Comments

@jeswr
Copy link
Contributor

jeswr commented Nov 20, 2023

Rather than

if (this.validateContext) {
try {
const parentContext = {...context, [key]: {...context[key]}};
delete parentContext[key]['@context'];
await this.parse(value['@context'],
{ ...options, external: false, parentContext, ignoreProtection: true, ignoreRemoteScopedContexts: true, ignoreScopedContexts: true });
} catch (e) {
throw new ErrorCoded(e.message, ERROR_CODES.INVALID_SCOPED_CONTEXT);
}
}
context[key] = {...value, '@context': (await this.parse(value['@context'],
{ ...options, external: false, minimalProcessing: true, ignoreRemoteScopedContexts: true, parentContext: context }))
.getContextRaw()}
I propose that this section of code look more like the following (note the disabling of minimal processing):

context[key] = {...value, '@context': (await this.parse(value['@context'],
          { ...options, external: false, ignoreRemoteScopedContexts: true, parentContext: context }))
          .getContextRaw()}

This is because this takes the same time as the try/catch call and prevents the parser from needing to re-expand the context during parsing thus reducing repeated operations.

This will also remove the need for caching objects in the context caching work.

@rubensworks
Copy link
Owner

I'm pretty sure we need the old code, to enforce the ERROR_CODES.INVALID_SCOPED_CONTEXT error, which is required by the spec in specific cases (see spec tests in the jsonld-streaming-parser).
But if you find another way to throw this specific coded error, then it's fine by me :-)

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

No branches or pull requests

2 participants