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

Prune tsconfig/all/tsconfig.json #1241

Closed
samreid opened this issue Apr 26, 2022 · 12 comments
Closed

Prune tsconfig/all/tsconfig.json #1241

samreid opened this issue Apr 26, 2022 · 12 comments

Comments

@samreid
Copy link
Member

samreid commented Apr 26, 2022

When we started on TypeScript, we used tsc to transpile files. Now we use babel for transpiling files, and only want to use tsc for type checking. We also have "checkJs": false in our tsconfig-core. Therefore, we no longer need to list all repos in all/tsconfig.json. This has the potential to speed up our type checking time, which has been a hassle.

Let's run before/after testing on the timing. I'll also compare to a monolithic tsc, which doesn't use project references at all.

The legacy tsconfig is in master.

Here is the pruned version:

{
  "extends": "../../tsconfig-core.json",
  // References to entry points that recursively visit the entire codebase
  // Sorted alphabetically
  "references": [
    {"path":"../../../bamboo"},
    {"path":"../../../build-a-nucleus"},
    {"path":"../../../buoyancy"},
    {"path":"../../../center-and-variability"},
    {"path":"../../../circuit-construction-kit-ac"},
    {"path":"../../../density"},
    {"path":"../../../geometric-optics-basics"},
    {"path":"../../../geometric-optics"},
    {"path":"../../../gravity-and-orbits"},
    {"path":"../../../greenhouse-effect"},
    {"path":"../../../mean-share-and-balance"},
    {"path":"../../../mobius"},
    {"path":"../../../models-of-the-hydrogen-atom"},
    {"path":"../../../my-solar-system"},
    {"path":"../../../number-play"},
    {"path":"../../../ratio-and-proportion"},
    {"path":"../../../simula-rasa"},
    {"path":"../../../tambo"},
    {"path":"../../../vegas"},
    {"path":"../../../wilder"},
  ],
  "files": [
    "../../phet-types.d.ts"
  ]
}

And here is the monolithic one:

/**
 * Shared defaults for tsconfig files.
 * @author Sam Reid (PhET Interactive Simulations)
 */
{
  "compilerOptions": {

    /* Basic Options */
    "incremental": true,                         /* Enable incremental compilation */
    "target": "ES2020",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
    "module": "ES2020",                          /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    // "lib": [],                                   /* Specify library files to be included in the compilation. */
    "allowJs": true,                             /* Allow javascript files to be compiled. */
    "checkJs": false,                            /* Report errors in .js files. */
    // "jsx": "preserve",                           /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
    "declaration": false,                         /* Generates corresponding '.d.js' file. */
    // "declarationMap": true,                      /* Generates a sourcemap for each corresponding '.d.js' file. */
    "sourceMap": false,                           /* Generates corresponding '.map' file. */
    "outDir": "./outdir",     /* Redirect output structure to the directory. */
    "rootDir": "../../../",                             /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    // "rootDir": "./",                             /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "composite": false,                             /* Enable project compilation */
    // "tsBuildInfoFile": "./",                     /* Specify file to store incremental compilation information */
    // "removeComments": true,                      /* Do not emit comments to output. */
     "noEmit": true,                              /* Do not emit outputs. */
    //    "emitDeclarationOnly": true,
    // "importHelpers": true,                       /* Import emit helpers from 'tslib'. */
    // "downlevelIteration": true,                  /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
    "isolatedModules": true,                     /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

    /* Strict Type-Checking Options */
    "strict": true,                              /* Enable all strict type-checking options. */
    // "noImplicitAny": true,                       /* Raise error on expressions and declarations with an implied 'any' type. */
    // "strictNullChecks": true,                    /* Enable strict null checks. */
    // "strictFunctionTypes": true,                 /* Enable strict checking of function types. */
    // "strictBindCallApply": true,                 /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
    // "strictPropertyInitialization": true,        /* Enable strict checking of property initialization in classes. */
    // "noImplicitThis": true,                      /* Raise error on 'this' expressions with an implied 'any' type. */
    // "alwaysStrict": true,                        /* Parse in strict mode and emit "use strict" for each source file. */

    /* Additional Checks */
    // "noUnusedLocals": true,                      /* Report errors on unused locals. */
    // "noUnusedParameters": true,                  /* Report errors on unused parameters. */
    "noImplicitReturns": true,                   /* Report error when not all code paths in function return a value. */
    // "noFallthroughCasesInSwitch": true,          /* Report errors for fallthrough cases in switch statement. */
    // "noUncheckedIndexedAccess": true,            /* Include 'undefined' in index signature results */
    "noImplicitOverride": true,                  /* Ensure overriding members in derived classes are marked with an 'override' modifier. */
    // "noPropertyAccessFromIndexSignature": true,  /* Require undeclared properties from index signatures to use element accesses. */

    /* Module Resolution Options */
    // "moduleResolution": "node",                  /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    // "baseUrl": "./",                             /* Base directory to resolve non-absolute module names. */
    // "paths": {},                                 /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
    // "rootDirs": [],                              /* List of root folders whose combined content represents the structure of the project at runtime. */
    // "typeRoots": [],                             /* List of folders to include type definitions from. */
    // "types": [],                                 /* Type declaration files to be included in compilation. */
    // "allowSyntheticDefaultImports": true,        /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    // "esModuleInterop": true,                     /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    // "preserveSymlinks": true,                    /* Do not resolve the real path of symlinks. */
    "allowUmdGlobalAccess": true,                /* Allow accessing UMD globals from modules. */

    /* Source Map Options */
    // "sourceRoot": "",                            /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "",                               /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,                     /* Emit a single file with source maps instead of having a separate file. */
    // "inlineSources": true,                       /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

    /* Experimental Options */
    // "experimentalDecorators": true,              /* Enables experimental support for ES7 decorators. */
    // "emitDecoratorMetadata": true,               /* Enables experimental support for emitting type metadata for decorators. */

    /* Advanced Options */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true        /* Disallow inconsistently-cased references to the same file. */
  },
  "files": [
    "../../../bamboo/js/bamboo-main.ts",
    "../../../build-a-nucleus/js/build-a-nucleus-main.ts",
    "../../../buoyancy/js/buoyancy-main.ts",
    "../../../center-and-variability/js/center-and-variability-main.ts",
    "../../../circuit-construction-kit-ac/js/circuit-construction-kit-ac-main.ts",
    "../../../density/js/density-main.ts",
    "../../../geometric-optics-basics/js/geometric-optics-basics-main.ts",
    "../../../geometric-optics/js/geometric-optics-main.ts",
    "../../../gravity-and-orbits/js/gravity-and-orbits-main.ts",
    "../../../greenhouse-effect/js/greenhouse-effect-main.ts",
    "../../../mean-share-and-balance/js/mean-share-and-balance-main.ts",
    "../../../mobius/js/mobius-main.ts",
    "../../../models-of-the-hydrogen-atom/js/models-of-the-hydrogen-atom-main.ts",
    "../../../my-solar-system/js/my-solar-system-main.ts",
    "../../../number-play/js/number-play-main.ts",
    "../../../ratio-and-proportion/js/ratio-and-proportion-main.ts",
    "../../../simula-rasa/js/simula-rasa-main.ts",
    "../../../tambo/js/tambo-main.ts",
    "../../../vegas/js/vegas-main.ts",
    "../../../wilder/js/wilder-main.ts",
    "../../phet-types.d.ts"
  ]
}

Running on Macbook Air M1

Experiment legacy pruned monolithic tsc
full check after clean 1m2.671s 0m25.886s 0m11.046s
tsc with no changes 0m1.159s 0m0.572s 0m2.775s
tsc with adding something1?: string; in NodeOptions 0m55.099s 0m10.944s 0m11.312s
tsc with adding this.age=7; in GOSim.ts 0m3.210s 0m3.150s 0m3.606s

It seems like the next step is to performance test on Windows.

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

On lenovo laptop with AMD Ryzen 7 5800H

Experiment legacy pruned monolithic tsc
full check after clean 1m42.494s 0m39.988s 0m18.903s
tsc with no changes 0m2.767s 0m1.378s 0m5.486s
tsc with adding something1?: string; in NodeOptions 1m37.187s 0m21.252s 0m19.848s
tsc with adding this.age=7; in GOSim.ts 0m6.850s 0m5.928s 0m6.163s

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

MSI desktop with Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz

Experiment legacy pruned monolithic tsc
full check after clean 2m1.649s 0m47.593s 0m21.340s
tsc with no changes 0m3.225s 0m1.713s 0m5.661s
tsc with adding something1?: string; in NodeOptions 2m6.030s 0m23.801s 0m21.061s
tsc with adding this.age=7; in GOSim.ts 0m7.615s 0m7.199s 0m7.155s

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

@jessegreenberg reported 2m33.717s and 0m4.211s for the legacy after clean and with no changes, on Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

Here is a bar chart showing mac (on the left), ryzen (middle) and core i7 (right)

image

For this issue, let's prune the tsconfig/all and open a side issue to discuss the monolithic version.

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

I identified that the pruned tsconfig above won't be checking the demo applications in common code repos, like sun-main, etc. since it is not included transitively. But adding that explicitly for all those repos didn't significantly change the time on Mac.

Before: 0m25.886s
After: 0m26.904s

I debated whether to request review before or after committing this to master. It seems a step in the right direction, and my local tests are working well, so perhaps I'll commit. I'll mark blocks-publication and reach out for a reviewer.

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

I wrote to our typescript slack channel:

@channel For #1241 I pushed a change to the all/tsconfig.json file to speed up type checking by a lot. For instance, on my Mac a clean type check was taking 1m2.671s. Now that is down to 27s. There are similar benefits on Win. Incremental type checks get an even bigger benefit.

It seems to be working nicely on my side, and I pushed the change to master. Can someone please volunteer to review?

Also, please review https://github.com/phetsims/chipper/blob/master/tsconfig/all/tsconfig.json and confirm the sim(s) you are currently working on are listed in that file. The riskiest part of this change is if a sim got dropped from that list. I generated that list by (a) sims that have a *-main.ts file or common code repos. Hopefully nothing was missed, but please add anything that was missed.

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

Also, if this disrupts your work for any reason and cannot be resolved quickly, please feel free to report and revert.

@samreid
Copy link
Member Author

samreid commented Apr 26, 2022

Also, I realized this doesn't speed up the precommit hooks at all, since they run tsc -b in the changed repo, not in the "all" tsconfig. But in phetsims/perennial#272 we may decide to run tsc -b on "all" for type checking common code repos.

@samreid
Copy link
Member Author

samreid commented Apr 28, 2022

@zepumph asks if grunt update should check: if there are any TS files, it should check that the sim is also listed in the all/tsconfig. Or is there any better way to automate generating/updating the all tsconfig.

@samreid
Copy link
Member Author

samreid commented Apr 28, 2022

@zepumph and I discussed getting rid of all the tsconfig files. That seems to have a good performance characteristic and we could get rid of a lot of complexity in our tsconfigs. The lint rule project could point to the monolithic one?

@samreid
Copy link
Member Author

samreid commented May 11, 2022

On hold until we discuss #1245

@samreid
Copy link
Member Author

samreid commented Jul 9, 2022

The new monolithic transitive tsconfigs have been working great, closing.

@samreid samreid closed this as completed Jul 9, 2022
samreid added a commit to phetsims/perennial that referenced this issue Oct 21, 2024
samreid pushed a commit to phetsims/perennial that referenced this issue Oct 21, 2024
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

1 participant