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

build: minify undici #53870

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

build: minify undici #53870

wants to merge 1 commit into from

Conversation

Kikobeats
Copy link

@Kikobeats Kikobeats commented Jul 16, 2024

Hi, I noticed that undici is not minified (none of the dependencies actually?).

It's big enough to be worth compressing to save half the space, but also to make it faster when it's required, not just using a normal require, also because undici contains lazy requires that are performed during the first fetch.

I know this is missing benchmarks, but wanted to hear what you think before continuing 🙂

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Jul 16, 2024
@juanarbol
Copy link
Member

I’m strongly -1 with this. I regularly have to debug Node.js JS layer. Minified JS almost means obfuscated JS. And I’m not sure about executing npx with an extra dependency. Not a fan of this change

@Kikobeats
Copy link
Author

@juanarbol Doesn't source maps fix that?

@MoLow
Copy link
Member

MoLow commented Jul 16, 2024

what are the numbers? how much does this improve the binary size?

@juanarbol
Copy link
Member

@juanarbol Doesn't source maps fix that?

It is not about that only. When code is obfuscated, it could impact performance as well. V8 is a capricious engine. This is not a lib for a CDN, having a bit more of extra bytes is not that critical (only for distributions, no in runtime). And it the thing about about bundle size; that means we will have to distribute the source maps for the debugging.

what are the numbers? how much does this improve the binary size?

Not sure if that will actually have impact, everything in JS will go thru' the js2c task.

Again, not the biggest fan of this, it introduces npx with a lib, not sure that is reliable, the "compressed" js output will require fixing the "esbuild" version, I mean; something else to maintain. And I don't see any factual value on this.

Still -1 on this, but maybe people from @nodejs/build could give a more objective opinion about this.

@juanarbol
Copy link
Member

@Kikobeats And congrats on the first contribution! Sorry for being that strict! You want to land something on a big project, we just needs to ensure we delivers the best -always-. Thanks for taking the time to contribute!

@avivkeller avivkeller added dependencies Pull requests that update a dependency file. build Issues and PRs related to build files or the CI. labels Jul 16, 2024
@avivkeller
Copy link
Member

avivkeller commented Jul 16, 2024

CC @nodejs/undici

@anonrig
Copy link
Member

anonrig commented Jul 16, 2024

I'm +1 if it's backed with data (benchmarks)

@Uzlopak
Copy link
Contributor

Uzlopak commented Jul 16, 2024

I am -1
I am pretty sure that you can compress the final executable, if you want to reduce the filesize. Under Windows you can use a so called PE-Packer. Dont know what is applicable for Linux or MacOS.
Obfuscating the code + the obligatory need then to somehow ship debug information via sourcemaps is imho annoying. Shipping a "node debug" with uncompressed deps could be unreliable, because the obfuscator/compressor could be transforming the code wrong.

@anonrig
Copy link
Member

anonrig commented Jul 16, 2024

I think the correct way to implement this is through having a build option called minify-js which only minifies when building for release.

@marco-ippolito
Copy link
Member

Afaik undici already goes through a build step, idk if location are preserved

@avivkeller
Copy link
Member

avivkeller commented Jul 16, 2024

I think the correct way to implement this is through having a build option called minify-js which only minifies when building for release.

I agree, because in my opinion, if minification were to occur, it should happen during build, allowing the debug build to retain the unminified sources.

@ronag
Copy link
Member

ronag commented Jul 16, 2024

I'm skeptical of the usefulness of this. -1

@metcoder95
Copy link
Member

-1

Copy link
Member

@KhafraDev KhafraDev left a comment

Choose a reason for hiding this comment

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

Although I doubt this will land due to the previous -1s, this currently will break class names and the node/undici user-agent header detection. It also doesn't lock esbuild to a specific version.
https://github.com/nodejs/undici/blob/d61af698dc50234289621c3613be9a8e42bf8e1f/package.json#L65

Without bundling, the deps-specific require that's used internally also won't work.

Copy link
Member

@panva panva left a comment

Choose a reason for hiding this comment

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

-1

I find very little, if any, value in this.

  • minification occasionally leads to behaviour changes which we wouldn't catch
  • stack traces provided by users in issues would be useless

Copy link
Contributor

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

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

👋 hi Kiko 😄

Unfortunately I don't believe we can support this. You can always supply your own, minified/optimized version of Undici and set it as the global dispatcher. May have a similar outcome.

@Uzlopak
Copy link
Contributor

Uzlopak commented Jul 17, 2024

After a meeting yesterday this PR is shining in a different light. It is about startup time of a node instance. Using a dispatcher is not the solution.

What if we use esbuild as a bundler and not as minifier. Maybe removing comments. This should improve the hoisting.

Is that improving the startup performance significantly?

@mertcanaltin
Copy link
Member

mertcanaltin commented Jul 17, 2024

After a meeting yesterday this PR is shining in a different light. It is about startup time of a node instance. Using a dispatcher is not the solution.

What if we use esbuild as a bundler and not as minifier. Maybe removing comments. This should improve the hoisting.

Is that improving the startup performance significantly?

I wonder if resource mappings can be used to resolve this?

example:

find "deps/undici/src" -type f -name "*.js" | while read -r file; do
  npx esbuild "$file" --minify --sourcemap --outfile="$file" --allow-overwrite
done

@KhafraDev
Copy link
Member

What if we use esbuild as a bundler and not as minifier. Maybe removing comments. This should improve the hoisting.

This is what we're already doing?

@Ethan-Arrowood
Copy link
Contributor

@KhafraDev and I already faced this previously for some optimization attempts. I believe we are bundling already. There are more esbuild optimizations we could try (such as comment removal iirc), but there are nuances to investigate carefully.

std-microblock added a commit to std-microblock/nanode that referenced this pull request Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. dependencies Pull requests that update a dependency file. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.