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(minifier): improve peephole-replace-known-methods #6490

Conversation

shulaoda
Copy link
Member

Support code similar to below:

`abc`['toUpperCase']()

Copy link

graphite-app bot commented Oct 13, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-minifier Area - Minifier label Oct 13, 2024
Copy link

codspeed-hq bot commented Oct 13, 2024

CodSpeed Performance Report

Merging #6490 will not alter performance

Comparing shulaoda:feat/improve-peephole-replace-known-methods (2a96897) with main (41c8675)

Summary

✅ 29 untouched benchmarks

@shulaoda shulaoda force-pushed the feat/improve-peephole-replace-known-methods branch from b810491 to 5772d79 Compare October 13, 2024 07:20
@shulaoda shulaoda force-pushed the feat/improve-peephole-replace-known-methods branch from a102a0d to 7dbd25c Compare October 13, 2024 07:49
Comment on lines -220 to +208
fold_same("x = `abcdef`.indexOf('b')");
fold("x = `abcdef`.indexOf('b')", "x = 1;");
Copy link
Contributor

Choose a reason for hiding this comment

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

Our test infra are ported from Google Closure Compiler, where it does not fold the template strings, and related code here: https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeReplaceKnownMethodsTest.java#L114.

@Boshen any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

@shulaoda The template string contains some expressions, but some of them can't be handled. There are already methods in place to replace template strings with normal strings when possible, and the minification process iterates multiple times rather than being a single pass. So, I believe we can focus on the string itself and not worry about template strings here. Everything else looks fantastic—thanks for your contribution!

Copy link
Contributor

Choose a reason for hiding this comment

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

So don't worry these tests here - after several times, from the template string, to the normal string, the minifier can handle this scenario :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

You are correct, I saw that the closure-compiler did recognize and convert the TemplateLiteral.

@shulaoda shulaoda marked this pull request as draft October 13, 2024 07:55
@shulaoda shulaoda marked this pull request as ready for review October 13, 2024 09:16
@shulaoda shulaoda force-pushed the feat/improve-peephole-replace-known-methods branch 2 times, most recently from 7c80f97 to 3bbf0f9 Compare October 13, 2024 09:20
Comment on lines +76 to +77
#[test]
fn test_get_string_literal() {
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know how to implement the test template and where to place it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have implemented a simple test case and temporarily placed it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend you to put it to src/node_util/mod.rs instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, I'm not sure if it's still necessary to exist. Because our TemplateLiteral seems to be able to be compressed into StringLiteral. I don't know if there are any specific scenarios that require this method.

@shulaoda shulaoda force-pushed the feat/improve-peephole-replace-known-methods branch from 3bbf0f9 to fba1884 Compare October 14, 2024 02:59
@shulaoda shulaoda changed the title feat(minifier): improve peephole-replace-known-methods feat(minifier): improve peephole-replace-known-methods Oct 14, 2024
@shulaoda shulaoda marked this pull request as draft October 14, 2024 08:13
@shulaoda shulaoda closed this Oct 14, 2024
@shulaoda shulaoda deleted the feat/improve-peephole-replace-known-methods branch February 24, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-minifier Area - Minifier
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants