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

feat(node): experimental trace support in @swc/core #3731

Merged
merged 7 commits into from
Feb 25, 2022

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Feb 24, 2022

Description:

This PR exposes new experimental interface __experimental_registerGlobalTraceConfig in @swc/core, allows generating event trace format based trace output for performance diagnose. Rust / node based CLI doesn't expose this flags yet.

The idea is pretty much same as #3066, PR adds some polishing & internal structures. Exposed interface itself may need some iteration, however it is exposed as __experimental for now. PR implements trace spans for es2015::arrow, generated trace confirms it is correct span with correct module (via category).

image

Notable changes in this PR is 40a96ae. I did add instrumentation spans for all of default visit_*, fold_* via swc_ecma_visit_macro and then back it out. Codewise it worked, but in practical it creates too verbose traces makes trace output unusable. For example, with macro support running transform over 150 file created trace larger than 700MB. It is nearly not possible to load on trace viewer as well.

In result, proposed approach in here is 9b2adee

  • for overridden visitor fn, add #[instrument] attr
  • that's it!

Only thing to note is I choose to use skip_all to not to include fn param into trace. Those are typically AST nodes, large enough to increase trace size.

Related issue (if exists):

@@ -77,6 +79,8 @@ pub fn print(

#[napi]
pub fn print_sync(program: String, options: Buffer) -> napi::Result<TransformOutput> {
crate::util::init_trace_once(false, None)?;
Copy link
Member Author

Choose a reason for hiding this comment

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

This repeated call is to preserve existing behavior to support ENV_LOG without breaking changes.

I hope to declare breaking changes to this eventually, by letting users explicitly opt in by calling trace registration.

@@ -69,6 +70,7 @@ struct Arrow {
impl VisitMut for Arrow {
noop_visit_mut_type!();

#[tracing::instrument(skip_all)]
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of manually creating span or use span! macro with hardcoded name, we'll use #instrument attr in general. We can always use span! or manual span for the cases we need additional customization but as a first step decorating all of our overridden visitor with default span would makes sense.

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

@kwonoj
Copy link
Member Author

kwonoj commented Feb 25, 2022

Yes, there's overhead to enable tracings on runtime binary. That is also noted in the original proposal as well. It is not uncommon though, large runtimes like chromium enables trace by default as it gives rich data for the performances on each user's machine. Overhead is a cost for those tradeoffs

The other alternative is not user-friendly in my opinion - either users have to opt in a specific binary, or run a native profiler which involves non-trivial setup for normal users. That's where I came to think we may be able to bite those cost.

@kwonoj
Copy link
Member Author

kwonoj commented Feb 25, 2022

Also per tokio-rs/tracing#1070, it looks like explicitly opt in specific trace level reduces those overhead. Updated PR to use trace level only.

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

LGTM.
Thank you!


swc-bump:

  • swc_ecma_transforms_compat

@kdy1 kdy1 enabled auto-merge (squash) February 25, 2022 03:52
@kdy1 kdy1 added this to the v1.2.146 milestone Feb 25, 2022
@kdy1 kdy1 merged commit a454996 into swc-project:main Feb 25, 2022
@kwonoj kwonoj deleted the feat-trace branch March 5, 2022 04:52
@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

3 participants