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

"Undefined Is Falsy": some further optimiations for project.json that are 100% compatible #3

Open
Flowermanvista opened this issue Sep 14, 2023 · 1 comment

Comments

@Flowermanvista
Copy link

When you try to access a named property of an Object in JavaScript, either by subscripting (foo["bar"]) or by dot notation (foo.bar), you'll either get the value of the property, or undefined if the property doesn't exist - you don't get a KeyError or anything like that. If you were checking if a property was true or not, you'd get the same result whether it existed with a false value, or if it didn't exist at all. We can take advantage of this to eliminate some unnecessary properties in project.json.

In my testing, the block properties "inputs", "fields", "shadow", and "topLevel" can all be excluded if they have false/empty values. This can save up to 52 bytes per block (plus ~3 extra bytes for the commas and all that).

I tested it on Paper Minecraft, and made sure that it worked properly in both online and desktop Scratch after my optimizations - here were my results:
Before compression: 4,835,853 bytes (92.2%)
After compression with ProjectJsonMinimizerNew: 3,538,267 bytes (67.5%)
After further compression: 2,855,259 bytes (54.5%) (~20% further size reduction)

Obviously, the results would be even more dramatic on projects that are more code-heavy and less data-heavy.

@Xeltalliv
Copy link
Owner

Interesting. I thought that something like this may be possible but I haven't really experimented with it.

One of my original goals when making minimizer was: if some unofficial tool can handle 100% of scratch projects created with original scratch editor, it shouldn't break when dealing with compressed projects. Even though scratch itself is fine with some properties missing, if scratch can't produce such projects, then I can't assume that other tools are designed to handle it.

I will still probably implement it in a separate "Dangerous" section or something

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

No branches or pull requests

2 participants