Giter VIP home page Giter VIP logo

Comments (5)

evanw avatar evanw commented on July 2, 2024 1

let is also slower than var. Both let and const require the VM to generate extra code to do additional checks that potentially throws an error if the variable is used before it's initialized. These checks can result in extreme slowdowns in older VMs and moderate slowdowns in newer VMs.

from esbuild.

evanw avatar evanw commented on July 2, 2024

Those two code fragments are basically the same size after gzip. If you aren't gzipping your code, then that's likely going to be a bigger win than any tweaks to the minifier can be. And if you are gzipping your code, then your suggestion will have essentially no effect on gzipped code size.

To answer your question: one easy way to avoid inlining is to replace const for var. That has the additional benefit of running more quickly as const has more run-time overhead than var does (at least when const is not completely inlined).

from esbuild.

nikitaeverywhere avatar nikitaeverywhere commented on July 2, 2024

Those two code fragments are basically the same size after gzip. If you aren't gzipping your code, then that's likely going to be a bigger win than any tweaks to the minifier can be. And if you are gzipping your code, then your suggestion will have essentially no effect on gzipped code size.

I knew you will say that! 😃

To answer your question: one easy way to avoid inlining is to replace const for var.

Very interesting insight, thank you! I see this also works with let (does it have similar runtime overhead?). Somewhat logical but surprising behavior, actually very useful in my case as I want to prevent substituting constants.

from esbuild.

nikitaeverywhere avatar nikitaeverywhere commented on July 2, 2024

Thank you, very insightful. As I additionally process the output code with terser, it transpiles everything to var.

I'm closing the issue then as there's a workaround, and somewhat I agree substituting const is an expected behavior. Thank you!

from esbuild.

evanw avatar evanw commented on July 2, 2024

Sounds good. Closing this issue then.

from esbuild.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.