statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
27.05k stars 1.24k forks source link

Poor Typescript Performance in editor? #1350

Closed mikecann closed 3 years ago

mikecann commented 4 years ago

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"]
}
davidkpiano commented 4 years ago

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.

Andarist commented 4 years ago

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
AlCalzone commented 4 years ago

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

mikecann commented 4 years ago

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.

davidkpiano commented 3 years ago

Closing this as a lot of TypeScript updates/changes have happened since this issue, and performance has improved.