Skip to content

Performance enhancement in jsonSchemaErrors: redundant disk I/O and duplicate instance conversion #189

@animeshsahoo1

Description

@animeshsahoo1

Here are the 2 performance enhancement we can do in jsonSchemaErrors
1. Localization.forLocale() reads from disk on every call
Every invocation of jsonSchemaErrors calls Localization.forLocale(), which reads the translation .ftl file from disk, parses it even when the language has not changed between calls.

export const jsonSchemaErrors = async (errorOutput, schemaUri, instance, options = {}) => {
  const normalizedErrors = await normalizedOutput(instance, errorOutput, schemaUri);
  const rootInstance = Instance.fromJs(instance);
  const localization = await Localization.forLocale(options.language ?? "en-US");
  return await getErrors(normalizedErrors, rootInstance, localization);
};

Solution: implement caching with simple Map for localization such that disk read occurs only once.

2. Instance.fromJs() called twice for the same input
Instance.fromJs(instance) is called once inside normalizedOutput and again in the outer jsonSchemaErrors function. Both calls receive the same instance value, meaning the conversion to AST is performed twice unnecessarily on every call.
Solution: call Instance.fromJs() once in jsonSchemaErrors and pass it into normalizedOutput instead of letting it recreate it again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions