-
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:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56629 +/- ##
========================================
Coverage 89.20% 89.21%
========================================
Files 662 662
Lines 191934 192079 +145
Branches 36944 36970 +26
========================================
+ Hits 171218 171360 +142
+ Misses 13552 13549 -3
- Partials 7164 7170 +6
|
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.
LGTM, just a comment
Isolate* isolate = args.GetIsolate(); | ||
CHECK(args[0]->IsString()); // TODO(joyeecheung): accept buffer. | ||
CHECK(args[1]->IsString()); | ||
CHECK(args[2]->IsUint32()); | ||
Local<Context> context = isolate->GetCurrentContext(); | ||
Environment* env = Environment::GetCurrent(context); |
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.
Isolate* isolate = args.GetIsolate(); | |
CHECK(args[0]->IsString()); // TODO(joyeecheung): accept buffer. | |
CHECK(args[1]->IsString()); | |
CHECK(args[2]->IsUint32()); | |
Local<Context> context = isolate->GetCurrentContext(); | |
Environment* env = Environment::GetCurrent(context); | |
Environment* env = Environment::GetCurrent(args); | |
CHECK(args[0]->IsString()); // TODO(joyeecheung): accept buffer. | |
CHECK(args[1]->IsString()); | |
CHECK(args[2]->IsUint32()); |
Then access env->isolate()
and env->context()
... I know we're not super consistent on this but would be nice to work towards more consistency
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.
If we are going to have more consistency, we should move away from using env->context()
as that makes the binding unusable for e.g. shadow realms, and prefer to do what's done here (i.e. use the current context, which makes it usable for shadow realms).
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.
Are these types of issues documented somewhere? Style guide updated? Shadow realm related concerns documented?
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.
I don't think "the right way to get context for situation X" is specifically documented, though it should be inferrable from the notes added in #47932 - if you want the binding to be reused in a different realm, don't use env->context()
when you mean "current context". There are still legit reasons to use env->context()
(when you actually mean the main context), but it's not here.
Isolate* isolate = args.GetIsolate(); | ||
Local<Context> context = isolate->GetCurrentContext(); | ||
Environment* env = Environment::GetCurrent(context); |
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.
Isolate* isolate = args.GetIsolate(); | |
Local<Context> context = isolate->GetCurrentContext(); | |
Environment* env = Environment::GetCurrent(context); | |
Environment* env = Environment::GetCurrent(args); |
Then use env->isolate()
before...
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.
Similar to before, we should refrain from using env->isolate()
and env->context()
at least for new code..
@@ -34,6 +41,7 @@ struct CompileCacheEntry { | |||
// Copy the cache into a new store for V8 to consume. Caller takes | |||
// ownership. | |||
v8::ScriptCompiler::CachedData* CopyCache() const; | |||
const char* type_name() const; |
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: std::string_view type_name() const;
?
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.
This is returning string literals for debug logs, doesn't that just adds an extra overhead for all of them?
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Tests appear to be failing due to the PR needing to be rebased. |
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).
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, as it's not exactly linear - it just skips transpilation altogether if it's already cached, so the more complex the file is, the more will be saved).
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