Skip to content

performance: expand contexts in parseInnerContexts #74

Open
@jeswr

Description

@jeswr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions