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

[Feature] Inline identity functions when minifying #907

Closed
natemoo-re opened this issue Mar 3, 2021 · 3 comments · Fixed by #1898
Closed

[Feature] Inline identity functions when minifying #907

natemoo-re opened this issue Mar 3, 2021 · 3 comments · Fixed by #1898

Comments

@natemoo-re
Copy link

natemoo-re commented Mar 3, 2021

Hello there! I know minification isn't the core focus of esbuild, but one very nice feature of terser is identity function inlining (see terser#510.) It would be nice if esbuild could optimize these functions away as well, as it's a pretty common pattern.

Input

const id = x => x;
const repro = [id(1), id(2)];
console.log(repro);

Current output

const id=o=>o,repro=[id(1),id(2)];console.log(repro);

Desired output

const repro=[1,2];console.log(repro);
@evanw
Copy link
Owner

evanw commented Mar 3, 2021

This isn't super straightforward to fix because doing this correctly would require inserting at least one more full-AST traversal after the scanning phase but before the linking phase. This would slow esbuild down and would work against the goal of having as few passes as possible for speed. So I'm not planning on having esbuild tackle these kinds of optimizations. At least not at the moment.

Another consideration is that the author of Terser is currently exploring a rewrite in Rust which should hopefully alleviate the huge performance impact of running Terser during a build. If that rewrite is successful, it might make less sense for esbuild to do all the work to replicate the advanced optimizations that Terser does if people can just run Terser after running esbuild instead.

Another similar request: #290.

@natemoo-re
Copy link
Author

That makes total sense, thank you for the quick and thorough response. As the docs mention, esbuild's minification is definitely within range of the alternatives—was just curious if this would be a quick optimization!

Going to close this as it seems out of scope for now.

@evanw
Copy link
Owner

evanw commented Jan 1, 2022

I implemented this for function declarations by the way. It was not a quick optimization, and it's a bit of a hack, but it should work now. See #1898 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants