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

minifier: alpha release #8264

Open
3 of 6 tasks
camc314 opened this issue Jan 5, 2025 · 5 comments
Open
3 of 6 tasks

minifier: alpha release #8264

camc314 opened this issue Jan 5, 2025 · 5 comments
Assignees
Labels
C-enhancement Category - New feature or request

Comments

@camc314
Copy link
Contributor

camc314 commented Jan 5, 2025

Tracking a range of misc minifier improvements vs esbuild

import("./empty_FIXTURE.js")(...[])  
import("./empty_FIXTURE.js")()  
  • 3. computed getter definitions in object literals
obj = { get[8]() { return "get string" } }  
obj = { get 8() { return "get string" } }  
  • 4. computed numeric property access to objects. NOTE: although esbuild performs this optimization, it may not be safe
obj["8"]  
obj[8]  
  1. remove unneccessary labels
  • 6. Use Exponential Notation for Large Numbers
1000000000.5  
1e9 + .5 
  1. inline single use const
const str = "1970-01-01[+00:00]";  
assert.sameValue(instance.equals(str))  
assert.sameValue(instance.equals("1970-01-01[+00:00]"))  
  • 8. normalize nullish comparisons
foo != undefined  
foo != null  
  • 9.
var x = () => !!delete foo;  
var x = () => delete foo;  
@camc314 camc314 added the C-enhancement Category - New feature or request label Jan 5, 2025
@camc314 camc314 self-assigned this Jan 5, 2025
@Boshen
Copy link
Member

Boshen commented Jan 6, 2025

I want to stabilize an alpha version this week, which consists of safe peephole optimizations, some refactorings, test clean up and documentation.

This leaves out:

  • inlining (7. inline single use const)
  • dead code removal (5. remove unneccessary labels)

@camc314 camc314 changed the title minifier: misc improvements tracking minifier: alpha release Jan 6, 2025
@Boshen
Copy link
Member

Boshen commented Jan 6, 2025

Current implementation of is_in_boolean_context is too hard to track, I may reimplement it by calling it on known boolean context positions, similar to how esbuild does it.

@Boshen
Copy link
Member

Boshen commented Jan 7, 2025

It seems like most peephole optimizations are done, time to stabilize:


Note: esbuild has a "bug" regarding constant folding multiplication, division and exponential - https://github.com/evanw/esbuild/blob/df815ac27b84f8b34374c9182a93c94718f8a630/internal/js_parser/js_parser.go#L10369-L10380

It "accidently" or "unintentially" folded more than it should, which lead to a bit of unstableness 😅

@Boshen Boshen self-assigned this Jan 8, 2025
@camc314
Copy link
Contributor Author

camc314 commented Jan 9, 2025

i am going to try port mangleStmts today/tommorow

mangleStmts

https://github.com/evanw/esbuild/blob/v0.24.2/internal/js_ast/js_ast_helpers.go#L2745

@Boshen
Copy link
Member

Boshen commented Jan 10, 2025

@camc314 Thank you.

Can we hold onto the the larger changes such as control flow optimizations and inlinings? Things get difficult when state tracking is required. But you may start implementing them, I won't be able to merge them until I stabilize everything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category - New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants