Skip to content
Discussions/App Development/How can I speed up Typescript compilation for my generated code?Forum ↗

How can I speed up Typescript compilation for my generated code?

App Development13 posts1,640 views16 likesLast activity Jul 2020
GE
georgOP
Apr 2020

During combined UI and DAML model development I often have to recompile DAML, regenerate the Typescript libraries and restart the sandbox. By far the most time is spent compiling the 20-odd Typescript projects generated from the codegen. Is there any trick or setting in tsconfig.json that I can use to speed up things? Maybe disabling some optimization or similar. The whole cycle is around 3mins long, which is not optimal for rapid development.

For everyone’s benefit, here is my handy Makefile, which at least makes invoking the cycle just a make:

build:
  daml build
  daml codegen ts -o daml2ts -p package.json .daml/dist/*.dar
  yarn workspaces run build
  daml start --start-navigator='no'
ST
stefanobaghino-da
Apr 2020

If you’re running on TypeScript 3.4+ you can probably try to enable incremental compilation as in the following example.

// tsconfig.json
{
    "compilerOptions": {
        "incremental": true,
        "outDir": "./lib"
    },
    "include": ["./src"]
}
GE
georg
Apr 2020

The problem seems to be that the tsconfig.json is generated as well, so it would need to be an option during code generation. @shaynefletcher maybe you have a view if that would yield a benefit. The other option would be not to regenerate the dependencies that didn’t change, such that if I change my own model only that would be regenerated. This would considerably improve the workflow.

CO
cocreature
Apr 2020

Making daml codegen js only regenerate the packages that have changed is definitely something that we want to do! I don’t have a great solution in the meantime sadly.

MA
ManishGrover
Apr 2020

If it helps, I believe this was compiling pretty fast (within less than a minute) before a recent change to the DAML UI Template

GE
georg
Apr 2020

@manishGrover yes, that’s because the UI template was updated to use the JS codegen recently.

GE
georg
Apr 2020

I found a workable solution:

After you’ve run yarn workspaces run build once, you’ll only need to recompile the one project that contains the generated code from your own DAML models. This is my new Makefile which works nicely:

build:
  daml build
  daml codegen ts -o daml2ts -p package.json .daml/dist/*.dar
  cd daml2ts/my-daml-model-0.0.1 && yarn build
  cd ui && yarn build
  daml start --start-navigator='no'

You’ll need to rerun yarn workspaces run build only when you upgrade the SDK version as then the generated packages for the standard libraries will be different.

CO
cocreature
Apr 2020

I believe this approach no longer works in the release candidate for 1.0 since daml2ts now produces JavaScript + TypeScript typings which means that it takes care of the compilation as part of running daml codegen ts.

GE
georg
Apr 2020

argh :man_facepalming: and there I was, happily accepting my answer…

In return for crushing my dreams, I’ve create this ticket for you :wink:

CO
cocreature
Apr 2020

Thanks, sorry for crushing your dreams :smiley:

CO
cocreature
Jul 2020

I couldn’t accept the fact that I’ve crushed your dreams so I’ve merged a PR yesterday that speeds up the JS codegen significantly (it now takes ~0.5s on the GSG as opposed to > 20s)

GE
georg
Jul 2020

:clap::muscle: Generating JS directly, thus skipping TS compilation entirely?

CO
cocreature
Jul 2020

Exactly we generate JS + typescript typings so from a user perspective you get the same output but we don’t have to run the typescript compiler which is super slow.

← Back to Discussions