-
Notifications
You must be signed in to change notification settings - Fork 63
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
new --strip option to build bundle #276
Conversation
Awesome! I've been wanting to implement this for a while but I instead relied on an external script to do it for me before bundling. The community on Discord have also had a conversation about this (multiple ones in fact), and a comparison between bundled: raw Lua code vs minified code vs the bytecode over here. First, this was in fact already implemented, but over in Lit, then later was removed in luvit/lit#263 for having bigger overall bundles and introducing a compatibility hell when building other apps. From my testing, this does in fact offer reduced size... a very big reduction. It only rarely resulted in slight overall size (with very small files), I tested it with multiple projects, mainly this project and inspect.lua, both resulted in a massive drop in size. The test was done as follows:
The results were as it follows:
It is also worth noting that the minified Lua code did result in a better overall size:
But that is impractical to implement and bundle, so it is out of the question. Seems like the main reason Lit failed at this was it didn't strip debugging symbols out (not passing the second argument of Remains the compatibility issue, which should not be present here as that was Lit mismatching Luvi versions. It does mean the compiled code will only work on the Luvi version that built it, but that sounds OK as it is never ran anywhere else really. Do note that in case Luvi was using Lua 5.1 or Lua 5.2 then the compiled bytecode will most likely be bigger in size than original, as those do not support the Overall I am in favor of this addition! I will also redo my tests using |
@zhaozg Seems like this should probably fallback to simply writing the un-compiled version of the string when it fails on
|
I've decided to test this for size by applying the patch and testing it directly, more representative like that. Also modified this a bit to solve the above issue and successfully bundle Lit, in luvibundle.lua: local ctx = bundle.readfile(child)
if strip and child:sub(-4, -1)=='.lua' then
local fn = load(ctx, child)
if fn then
ctx = string.dump(ctx, strip)
end
end
writer:add(child, ctx, 9)
end The "Normal" type will use an unpatched version of Luvi ran using Bundling latest Luvit:
Bundling latest Lit:
Bundling inspect.lua (as a single main.lua):
(Should I test other things out?) Seems like overall, there is a size improvement although it is somewhat negligible, in case of inspect.lua the size of the stripped version was slightly bigger. I think this is fine, as long as it is not an increase in size (most often) then the rest of the use cases this will support are worth it. |
Do you really want to bundle lua code with errors, I think we can give more solution.
|
package.lua as metatadata in luvit world
cc @luvit/luvit-admin |
It seems like the new default behavior without any options is to compile the Lua but not strip, but I think Here's my preference for what the help should look like:
|
Ok, I'll fix. I prefer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is going to be the case:
local compile = options.strip or options.compile
then I think these suggested changes make sense. Alternatively, we could make --strip
do nothing unless --compile
is set.
I don't have a preference for which we should do.
Is this easy to be ambiguous? |
@squeek502 thanks your code review. A nice and meticulous person. |
mainly to hide Lua source code, and size and speed are byproduct.