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

Reuse generator when possible #18

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

roni-frantchi
Copy link

Building a schema generator (more precisely, building the TypeScript program it uses), is very costly.
Trials show 5-6s in large projects.

Right now if JsonSchema.fromType<>() is used n times, this generator (and the TypeScript program that comes with it), will be built n times.

In most cases, the generator and its program can be reused - shaving off precious build minutes and memory pressure.
The only exception is when JsonSchema.fromType<>() is given the optional argument to change the generator config - in this case, a new generator will be built and used instead of the default one.

So in most cases, this PR will introduce an optimization making the transformer it n times faster.

Next optimization steps

Since we're running within a TypeScript program, maybe we'd would be able to reuse the program that is being transpiled right now instead of creating a new one.

That should shave off those final seconds.

const formatter = tjs.createFormatter(config);
const parser = tjs.createParser(program, config);
const generator = new tjs.SchemaGenerator(program, parser, formatter, config);
const schema = generator.createSchema(config.type);

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

Successfully merging this pull request may close these issues.

2 participants