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

refactor(es/compat): Use special span instead of passing static_blocks_mark #9725

Merged
merged 8 commits into from
Nov 14, 2024

Conversation

magic-akari
Copy link
Member

Description:

Let's make an assumption in the code: the use of dummy span as a private class field name is generated by us, it is there simply because it is necessary to maintain the order of side effect execution, its name is not referenced elsewhere, so we can safely remove its name.

This is a breaking change for Rust users.

BREAKING CHANGE:

Related issue (if exists):

Copy link

changeset-bot bot commented Nov 9, 2024

🦋 Changeset detected

Latest commit: 586b38b

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codspeed-hq bot commented Nov 9, 2024

CodSpeed Performance Report

Merging #9725 will degrade performances by 8.27%

Comparing magic-akari:refactor/static-blocks (586b38b) with main (aa0f784)

Summary

❌ 2 regressions
✅ 192 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main magic-akari:refactor/static-blocks Change
es/full/base/fixer 116.8 µs 127.4 µs -8.27%
es/visitor/base-perf/boxing_unboxed_clone 2.6 µs 2.6 µs -3.32%

@magic-akari magic-akari marked this pull request as ready for review November 9, 2024 18:26
@magic-akari magic-akari requested a review from a team as a code owner November 9, 2024 18:26
@kdy1 kdy1 added this to the Planned milestone Nov 11, 2024
@kdy1 kdy1 self-assigned this Nov 11, 2024
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.

What if plugin authors create a private name with dummy spans?

I think some plugins related to decorators may generate some private names, and if it's the case, most of the plugin authors will simply use dummy span (at least initially)

@magic-akari
Copy link
Member Author

Unfortunately, we have already used a similar trick here

// Black magic to detect injected constructor.
let is_constructor_default = constructor.span.is_dummy();
if is_constructor_default {
debug!("Dropping constructor parameters because the constructor is injected");
constructor.params = Vec::new();
}

Or here

// Black magic to detect injected constructor.
let is_constructor_default = constructor.span.is_dummy();
if is_constructor_default {
debug!("Dropping constructor parameters because the constructor is injected");
constructor.params.take();
}

@kdy1
Copy link
Member

kdy1 commented Nov 11, 2024

Hmm. Makes sense. I'll review this PR later today.

@magic-akari
Copy link
Member Author

magic-akari commented Nov 11, 2024

Or should we add another special span?

By the way: We added PURE_SP last time, but we didn't add the documentation properly.


I personally prefer to use dummy span directly.

@kdy1
Copy link
Member

kdy1 commented Nov 11, 2024

I didn't think deeply enough while writing the DUMMY_SP hack because there was no Wasm plugin API, and I introduced static_block_mark because there's a custom plugin API at the moment of writing.

We may introduce another special flag in bytepos like SYNTHESIZED, one more for the Span type and use it, like you suggested.

Also, can you add a bit of documentation?

@magic-akari magic-akari requested a review from a team as a code owner November 12, 2024 14:17
@magic-akari magic-akari changed the title refactor(es/compat): Use dummy span instead of passing static_blocks_mark refactor(es/compat): Use special span instead of passing static_blocks_mark Nov 14, 2024
@kdy1 kdy1 merged commit 6ad0735 into swc-project:main Nov 14, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants