-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
module: integrate TypeScript into compile cache #56629
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
This integrates TypeScript into the compile cache by caching the transpilation (either type-stripping or transforming) output in addition to the V8 code cache that's generated from the transpilation output. Locally this speeds up loading with type stripping of `benchmark/fixtures/strip-types-benchmark.ts` by ~65% and loading with type transforms of `fixtures/transform-types-benchmark.ts` by ~128%. When comparing loading .ts and loading pre-transpiled .js on-disk with the compile cache enabled, previously .ts loaded 46% slower with type-stripping and 66% slower with transforms compared to loading .js files directly. After this patch, .ts loads 12% slower with type-stripping and 22% slower with transforms compared to .js. (Note that the numbers are based on microbenchmark fixtures and do not necessarily represent real-world workloads, though with bigger real-world files, the speed up should be more significant).
* @typedef {object} TypeScriptOptions | ||
* @property {'transform'|'strip-only'} mode Mode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, so you can avoid repeating 'strip-only'|'transform'
later
* @typedef {object} TypeScriptOptions | |
* @property {'transform'|'strip-only'} mode Mode. | |
* @typedef {'strip-only' | 'transform'} TypeScriptMode | |
* | |
* @typedef {object} TypeScriptOptions | |
* @property {TypeScriptMode} mode Mode. |
@@ -108,6 +120,20 @@ function processTypeScriptCode(code, options) { | |||
return transformedCode; | |||
} | |||
|
|||
/** | |||
* Get the type enum used for compile cache. | |||
* @param {'strip-only'|'transform'} mode Mode of transpilation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per above.
* @param {'strip-only'|'transform'} mode Mode of transpilation. | |
* @param {TypeScriptMode} mode Mode of transpilation. |
case CachedCodeType::kStrippedTypeScript: | ||
return "StrippedTypeScript"; | ||
case CachedCodeType::kTransformedTypeScript: | ||
return "TransformedTypeScript"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this flavor exist? I thought if we were transforming, we were adding source maps. Is there a way to transform without getting source maps?
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56629 +/- ##
========================================
Coverage 89.20% 89.21%
========================================
Files 662 662
Lines 191890 192027 +137
Branches 36928 36956 +28
========================================
+ Hits 171176 171309 +133
- Misses 13554 13555 +1
- Partials 7160 7163 +3
|
This integrates TypeScript into the compile cache by caching the transpilation (either type-stripping or transforming) output in addition to the V8 code cache that's generated from the transpilation output.
Locally this speeds up loading with type stripping of
benchmark/fixtures/strip-types-benchmark.ts
by ~65% and loading with type transforms offixtures/transform-types-benchmark.ts
by ~128%.When comparing loading .ts and loading pre-transpiled .js on-disk with the compile cache enabled, previously .ts loaded 46% slower with type-stripping and 66% slower with transforms compared to loading .js files directly.
After this patch, .ts loads 12% slower with type-stripping and 22% slower with transforms compared to .js.
(Note that the numbers are based on microbenchmark fixtures and do not necessarily represent real-world workloads, though with bigger real-world files, the speed up should be more significant).
There are some TODOs left for avoiding the excessive UTF8 transcoding, which depends on swc-project/swc#9851 though the numbers are already good enough that I think that can be done as a follow-up..when swc actually supports it.
With compile cache enabled via
export NODE_COMPILE_CACHE=/tmp
:Without compile cache (i.e. there should be no regression when it's not enabled):
Fixes: #54741