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

Use caches for module resolution and type reference directives when using compiler default functions #1287

Merged
merged 12 commits into from
Apr 22, 2021

Conversation

sheetalkamat
Copy link
Contributor

@sheetalkamat sheetalkamat marked this pull request as ready for review April 20, 2021 19:06
@JasonKleban
Copy link

@johnnyreilly could this please be also get applied to version 8.x for webpack 4 compatibility?

@JasonKleban
Copy link

What is the technique for testing both this and the typescript branch locally at once?

@johnnyreilly
Copy link
Member

@johnnyreilly could this please be also get applied to version 8.x for webpack 4 compatibility?

If you wanted to do a PR to backport it against the https://github.com/TypeStrong/ts-loader/tree/webpack-4 branch after this has been merged then we could potentially look at it.

@sheetalkamat
Copy link
Contributor Author

@johnnyreilly I am not sure what the test failures mean but i am able to successfully run the tests locally.
This is ready to merge pending review.

@sheetalkamat
Copy link
Contributor Author

@JasonKleban I had to manually create links for typescript built locally while I was working on this and ts-loader as well and use it in your sample repro. That's how I tested it, not sure if that's how you would need to test but bot should post typescript build from the PR at microsoft/TypeScript#43700 (comment)

@johnnyreilly
Copy link
Member

@johnnyreilly I am not sure what the test failures mean but i am able to successfully run the tests locally.
This is ready to merge pending review.

Thanks @sheetalkamat - looking at the test failure it looked like a random yarn failure. I've requeued and will try to make time to do the review soon. Thanks for your efforts!

@JasonKleban
Copy link

@sheetalkamat can you share any indication for how big of a performance impact you expect this to have? Might it nearly equalize ts-loader & webpack to tsc compilation times?

@sheetalkamat
Copy link
Contributor Author

sheetalkamat commented Apr 21, 2021

Might it nearly equalize ts-loader & webpack to tsc compilation times?

@JasonKleban probably.. The sample was such a small, that I couldn't measure it reliably especially with my local setup but i did verify that lot of file accesses and checks get reduced (esp you can see that in trace logs). Because of the way ts-loader works(i am not sure if it is intentional or not but I didn't go about investigating that) i have seen that program is created with some subset of files and more files get added to it as webpack asks about more information about dependencies.. So in that second pass, you start reusing module resolution, type reference resolution, package.json cache etc... Note that package.json improvement can be seen (from trace logs) for semver types as well as it tries to read package.json many times the first time itself.

Btw typescript PR build is available at microsoft/TypeScript#43700 (comment)

src/interfaces.ts Outdated Show resolved Hide resolved
src/servicesHost.ts Outdated Show resolved Hide resolved
src/servicesHost.ts Outdated Show resolved Hide resolved
Copy link
Member

@johnnyreilly johnnyreilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Fine work @sheetalkamat!

I'm happy for this to be released and I've updated the package.json / CHANGELOG.md accordingly.

@@ -6,10 +6,10 @@ asset ../../lib/tsconfig.tsbuildinfo 2.73 KiB [emitted]
cached modules 408 bytes [cached] 2 modules
./src/index.ts 108 bytes [built] [code generated] [1 error]

ERROR in app/src/index.ts
ERROR in app\src\index.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm? why is this a backslash?

btw. webpack usually would display this as ERROR in ./app/src/index.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is just ts-loader surfacing up what TypeScript hands over:

const file = diagnostic.file;

So if you're running on a Windows machine it's likely \ country

JasonKleban pushed a commit to JasonKleban/ts-loader that referenced this pull request Apr 22, 2021
johnnyreilly added a commit that referenced this pull request Apr 23, 2021
* Backport "Use caches for module resolution and type reference directives when using compiler default functions" #1287 to v8

* regen comparison tests

* Revert "regen comparison tests"

This reverts commit f04c5cf.

* only the two failing tests rerun.

* yarn run comparison-tests -- --save-output --single-test projectReferencesSymLinks

* yarn run comparison-tests -- --single-test projectReferencesSymLinks_WatchApi --save-output

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
Co-authored-by: John Reilly <johnny_reilly@hotmail.com>
@felixmosh
Copy link

I'm getting an error with v9.1.0-9.1.1, since this is the only change in these versions, I post it here

[webpack-cli] HookWebpackError: Cannot read property 'length' of undefined
    at makeWebpackError (/Users/***/Projects/node/***/node_modules/webpack/lib/HookWebpackError.js:49:9)
    at /Users/***/Projects/node/***/node_modules/webpack/lib/Compilation.js:2496:12
    at eval (eval at create (/Users/***/Projects/node/***/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:26:1)
    at fn (/Users/***/Projects/node/***/node_modules/webpack/lib/Compilation.js:427:17)
    at Hook.eval [as callAsync] (eval at create (/Users/***/Projects/node/***/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:24:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/***/Projects/node/***/node_modules/tapable/lib/Hook.js:18:14)
    at cont (/Users/***/Projects/node/***/node_modules/webpack/lib/Compilation.js:2493:34)
    at /Users/***/Projects/node/***/node_modules/webpack/lib/Compilation.js:2539:10
    at /Users/***/Projects/node/***/node_modules/neo-async/async.js:2830:7
    at Object.each (/Users/***/Projects/node/***/node_modules/neo-async/async.js:2850:39)
-- inner error --
TypeError: Cannot read property 'length' of undefined
    at computeLineStarts (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:9580:27)
    at Object.getLineStarts (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:9640:60)
    at getCurrentLineMap (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:101516:59)
    at emitDetachedCommentsAndUpdateCommentsInfo (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:105227:94)
    at emitBodyWithDetachedComments (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:105067:17)
    at emitSourceFile (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:103774:21)
    at pipelineEmitWithHint (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:101597:24)
    at noEmitNotification (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:100109:9)
    at onEmitNode (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:85991:13)
    at onEmitNode (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:96421:17)
caused by plugins in Compilation.hooks.processAssets
TypeError: Cannot read property 'length' of undefined
    at computeLineStarts (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:9580:27)
    at Object.getLineStarts (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:9640:60)
    at getCurrentLineMap (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:101516:59)
    at emitDetachedCommentsAndUpdateCommentsInfo (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:105227:94)
    at emitBodyWithDetachedComments (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:105067:17)
    at emitSourceFile (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:103774:21)
    at pipelineEmitWithHint (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:101597:24)
    at noEmitNotification (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:100109:9)
    at onEmitNode (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:85991:13)
    at onEmitNode (/Users/***/Projects/node/***/node_modules/typescript/lib/typescript.js:96421:17)
error Command failed with exit code 2.

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

Successfully merging this pull request may close these issues.

5 participants