Skip to content

base64_encode embedded data files #14526

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

Merged
merged 4 commits into from
Jun 25, 2021
Merged

Conversation

crudelios
Copy link
Contributor

When file_packager --embed (or emcc --embed-file) is used, this change reduces the embedded data size by about 75%.

It also plays nicer with the acorn optimizer, making it use less RAM when there is embedded data.

Do note that, as reported in #14482, the acorn optimizer still uses a lot of RAM, which possibly can be improved (that is way beyond my knowledge of this project). However, since the final html is now much smaller, less RAM is used by the optimizer as well.

Reduces the embedded data size by about 75%
It also plays nicer with the acorn optimizer, making it use less RAM when there is embedded data
@welcome
Copy link

welcome bot commented Jun 23, 2021

Thank you for submitting a pull request! If this is your first PR, make sure to add yourself to AUTHORS.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Looks good aside from one proposed change.

@@ -398,7 +398,7 @@ function JSify(functionsOnly) {
print(preprocess(read('arrayUtils.js')));
}

if (SUPPORT_BASE64_EMBEDDING && !MINIMAL_RUNTIME) {
if ((SUPPORT_BASE64_EMBEDDING || FORCE_FILESYSTEM) && !MINIMAL_RUNTIME) {
Copy link
Member

Choose a reason for hiding this comment

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

How about replacing this specific change with this:

diff --git a/emcc.py b/emcc.py
index eaf519567..269e5cebb 100755
--- a/emcc.py
+++ b/emcc.py
@@ -1877,6 +1877,10 @@ def phase_linker_setup(options, state, newargs, settings_map):
   else:
     settings.SYSTEM_JS_LIBRARIES.append((0, shared.path_from_root('src', 'library_pthread_stub.js')))
 
+  if settings.FORCE_FILESYSTEM:
+    # enable base64 decoding for file packager data
+    settings.SUPPORT_BASE64_EMBEDDING = 1
+
   if settings.FORCE_FILESYSTEM and not settings.MINIMAL_RUNTIME:
     # when the filesystem is forced, we export by default methods that filesystem usage
     # may need, including filesystem usage from standalone file packager output (i.e.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason I didn't do it that way is because using SUPPORT_BASE64_EMBEDDING has side effects which I'm not sure are needed in this case. Specifically, enabling SUPPORT_BASE64_EMBEDDING adds some calls in the code to tryParseAsDataURI, which wouldn't be called otherwise.

However, if that's OK, then sure,it's easier to just enable SUPPORT_BASE64_EMBEDDING 👍

Copy link
Member

Choose a reason for hiding this comment

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

Oh, very good point. Yes, thinking on this more carefully, I agree with you.

@@ -57,6 +57,7 @@
subdir\file, in JS it will be subdir/file. For simplicity we treat the web platform as a *NIX.
"""

import base64
Copy link
Member

Choose a reason for hiding this comment

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

Nice that python makes this easy...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah is was rather easy to encode the files. Adding decoding was a little trickier but not by much, it's a small change with a visible impact.

@kripken
Copy link
Member

kripken commented Jun 25, 2021

Odd, one of the commits mentions adding yourself to AUTHORS, but I don't see it in the final code - ? (That's the last thing to do before merging this.)

@crudelios
Copy link
Contributor Author

crudelios commented Jun 25, 2021

Yes I did notice that, for some reason the file didn't change (maybe I forgot to save it?). I was waiting to see if I had any other change to do and I'd add it then. I'll add that change now.

@kripken kripken merged commit 660dcc0 into emscripten-core:main Jun 25, 2021
@sbc100
Copy link
Collaborator

sbc100 commented Jan 19, 2022

Hopefully #16050 will make this even more efficient and even avoid copies completely.

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 this pull request may close these issues.

3 participants