Support asynchronous schema loading in `SchemaJsonLocater`
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:
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.
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?
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;
}
}