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

Support asynchronous schema loading in SchemaJsonLocater #6714

Open
grigasp opened this issue May 13, 2024 · 2 comments
Open

Support asynchronous schema loading in SchemaJsonLocater #6714

grigasp opened this issue May 13, 2024 · 2 comments
Assignees
Labels
ecschema Issues related to the various ecschema packages

Comments

@grigasp
Copy link
Member

grigasp commented May 13, 2024

Is your feature request related to a problem? Please describe.

At the moment SchemaJsonLocater loads requested schema synchronously, which causes the main thread to block when loaded schema is large or has many referenced schemas. Example:

image

Describe the solution you'd like

I'd like SchemaJsonLocater.getSchema to have an asynchronous implementation instead of relying on a synchronous one.

Describe alternatives you've considered

As a workaround, I extended SchemaJsonLocater and provided my own asynchronous implementation for getSchema.

@grigasp grigasp added the ecschema Issues related to the various ecschema packages label May 13, 2024
@ColinKerr
Copy link
Member

This is a known issue, #6674 I have bumped up the priority of this issue because you're seeing perf issues related to it. I'm also leaving both open because they have unique info.

Can you provide the async version you implemented?

@grigasp
Copy link
Member Author

grigasp commented May 15, 2024

This is a known issue, #6674 I have bumped up the priority of this issue because you're seeing perf issues related to it. I'm also leaving both open because they have unique info.

Can you provide the async version you implemented?

class AsyncSchemaJsonLocater extends SchemaJsonLocater {
  #_getSchema: SchemaPropsGetter;
  public constructor(getSchema: SchemaPropsGetter) {
    super(getSchema);
    this.#_getSchema = getSchema;
  }
  public override async getSchema<T extends Schema>(
    schemaKey: Readonly<SchemaKey>,
    _matchType: SchemaMatchType,
    context: SchemaContext,
  ): Promise<T | undefined> {
    const schemaProps = this.#_getSchema(schemaKey.name);
    if (!schemaProps) {
      return undefined;
    }

    await BeDuration.wait(0);
    const schema = await Schema.fromJson(schemaProps, context);
    return schema as T;
  }
}

@RohitPtnkr1996 RohitPtnkr1996 self-assigned this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecschema Issues related to the various ecschema packages
Projects
None yet
Development

No branches or pull requests

3 participants