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

Feature request: Improve performance when compiling enormous files #323

Closed
navndn opened this issue Jul 17, 2020 · 10 comments
Closed

Feature request: Improve performance when compiling enormous files #323

navndn opened this issue Jul 17, 2020 · 10 comments

Comments

@navndn
Copy link

navndn commented Jul 17, 2020

This is probably a bug, compilation hangs for HL7 FHIR Json-schema.

FHIR schema is quite large, around 60k lines

Official link to download fhir.schema.json :
https://www.hl7.org/fhir/fhir.schema.json.zip

It hangs on both Windows & Ubuntu.
Any clue on this?

CLI:
json2ts -i fhir.schema.json -o fhir.d.ts

No luck with program too,

const schema = JSON.parse(
  fs.readFileSync(path.resolve(__dirname, 'fhir.schema.json'), 'utf8')
);

compile(schema, 'FHIRSchema')
  .then(ts => fs.writeFileSync('fhir.d.ts', ts))
  .catch(console.error);

There is already a related issue #222 , but the original tittle doesn't specify HL7 FHIR schema.

@saulide
Copy link

saulide commented Oct 27, 2020

Any update? Due to COVID, this is kind of helpfull

@dinbtechit
Copy link

Having same issue here! unable to generate the .ts files. Is it possible to break this into smaller files?

bcherny pushed a commit that referenced this issue Nov 29, 2020
@bcherny
Copy link
Owner

bcherny commented Nov 29, 2020

3.3mb it pretty hefty. 600kb -- the biggest test case so far -- seems to work fine. Even when disabling formatting (running Prettier is by far the slowest part of compilation), JSTT hangs when run as part of a test case.

Can you try disabling formatting --format=false and trying again?

If it still hangs: I merged a test case for this issue, and disabled it for now. Whoever wants to take a shot at speeding up the compiler:

  1. Clone this repo

  2. Rename /test/e2e/realWorld.fhir.ignore.ts to test/e2e/realWorld.fhir.ts

  3. Edit test/e2e/realWorld.fhir.ts, and add the following line to tell the test runner to only run this file:

    export const only = true
  4. Edit src/parser.ts, and comment out the couple of log() calls to avoid terminal spam

  5. Run the tests: yarn test (or, VERBOSE=true yarn test to also get perf telemetry)

@bcherny bcherny changed the title [BUG] Compilation hangs for HL7 FHIR Json-schema Feature request: Improve performance when compiling enormous files Nov 29, 2020
@bcherny
Copy link
Owner

bcherny commented Jan 8, 2021

Hey @navndn @saulide @dinbtechit, mind trying again with the latest version (v10.1.2)? @G-Rath just landed a big perf improvement in #361.

@G-Rath
Copy link
Contributor

G-Rath commented Jan 8, 2021

I had a play around with this locally, and it seems the issue is with the amount of dereferencing that needs to be done:

image
(I killed the process after it'd been running for around 3 minutes).

Our schema.json (that is now compiling in ~3 seconds instead of ~120 seconds) is 1.1mb in size.

@bcherny
Copy link
Owner

bcherny commented Jan 9, 2021

@G-Rath If that's right, could be worth filing an issue for json-schema-ref-parser?

@G-Rath
Copy link
Contributor

G-Rath commented Jan 10, 2021

Yeah, probably - I'll look to do that if I have the time and a good reproduction case (I don't mind doing it, but also I've not got a lot context on the underlying issue other than hacking around, so might not be able to dedicate enough time to the issue to provide the info that's required for the maintainers).

I hacked memorize into crawl and that seems to unblock that phase of the pipeline - parsing then takes a couple of seconds but is very fast (probably because of the new memorization happening there).

So then the blocker becomes optimize - this schema results in a union of 146 members, which means lodash.uniqBy has to do a lot of work via stringify:

image

image

I'm toying around with the code in those areas to see if they can be improved with caching, but it's really not looking promising :/

@bcherny
Copy link
Owner

bcherny commented Jan 10, 2021

@G-Rath Thanks for digging in, and for documenting what you're finding. Even if you don't manage to get to the bottom of it, these will be great breadcrumbs for the next person to dig in!

@G-Rath
Copy link
Contributor

G-Rath commented Jan 18, 2021

Apparently there's going to be a new kid on the block that'll replace json-schema-ref-parser so will have to wait for that to come out before making an issue to improve performance, as it sounds like json-schema-ref-parser is in maintenance mode.

@bcherny
Copy link
Owner

bcherny commented Jun 29, 2022

Published as part of v11.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants