Xstate: Poor Typescript Performance in editor?

Created on 2 Aug 2020  路  4Comments  路  Source: davidkpiano/xstate

Description
This is a difficult one to lockdown, but I have searched the issues and surprisingly couldnt find a mention of other issues.

It seems like the typescript performance in the editor is really poor. I suspect this is to to lots of type aliasing and other complex type inferrence rules.

Theres probably not a lot that can be done about it but I thought I would open an issue anyways.

Expected Result
Intellisense should be fast

Actual Result
Its noticably slow even on this 6-core intel-i9 desktop PC

Reproduction

  1. Take an example such as the light machine from the docs (https://xstate.js.org/docs/guides/typescript.html#using-typescript)
  2. Create an interpreter (const interpreter = interpret(lightMachine);) and then type interpreter and press . and notice the time taken for the intellisense window to open.

An example video here: https://www.dropbox.com/s/jawsfq8frfop4aw/cbrJVjwwlr.mp4?dl=0

This is best case as im running on a powerful desktop PC, less powerful laptops would probably be much slower.

Additional context
Latest version of XState and Typescript, tsconfig looks like:

{
  "compilerOptions": {
    "outDir": "dist",
    "sourceMap": true,
    "module": "commonjs",
    "target": "es6",
    "lib": ["dom", "esnext"],
    "incremental": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  },
  "include": ["./src/**/*.ts", "./scripts/**/*.ts", "./test/**/*.ts"]
}

typescript

Most helpful comment

FYI, it seems that strictFunctionTypes: true massively improves the performance.

All 4 comments

This is likely fixed in master: https://github.com/microsoft/TypeScript/issues/39826 .

You can install from a GitHub link and try it out - please let me know if performance is improved.

Unfortunately, it's not possible to install monorepo packages from github when using npm (there is no way to specify which directory should be installed). I've heard that Yarn 2 has a syntax for this though.

However, I think it should be possible to install the current master using one of those thanks to our CodeSandbox CI integration:

yarn add https://pkg.csb.dev/davidkpiano/xstate/commit/53d0dd5b/xstate 
npm i https://pkg.csb.dev/davidkpiano/xstate/commit/53d0dd5b/xstate

FYI, it seems that strictFunctionTypes: true massively improves the performance.

Awesome thanks @AlCalzone, im just waiting for the dust to settle in https://github.com/microsoft/TypeScript/issues/39826 before I have another go at this.

Was this page helpful?
0 / 5 - 0 ratings