Minimizing v8 build size

4,403 views
Skip to first unread message

Matt Kline

unread,
Aug 27, 2014, 8:38:51 PM8/27/14
to v8-u...@googlegroups.com
Hi all,

I'm attempting to build V8 on three platforms: Linux on x86, Linux on ARM via a GCC cross-compiler, and Windows. I'm trying to minimize the library size, and am left with a few questions. I realize this topic has come up before in the mailing list, but most of the posts seem to be years old before GYP was used.

  1. On Linux, I get an approximately 20 MB executable given the default flags. Is this about as small as V8 can be expected to get? Besides -Os, are there other flags I can provide or features I can disable in order to get a smaller size? V8 is being used to parse PAC scripts in this scenario, so it is assumed that the JavaScript files will be pretty small and execution speed isn't critical.

  2. On Windows, I'm building with Visual Studio. After running "python build\gyp_v8" and building All.sln, I get a v8_base.lib that's over 160 MB. Clearly this can be slimmed down, given the build size I got on Linux. I was able to reduce it to about 38 MB by setting "Debug Information Format" to "None" and optimization flags to "Minimum Size" (/O1) and "Favor small code" (/Os), but that's still twice as large as my Linux build, and that's not even counting the other .lib files. What other options should I be setting?

Louis Santillan

unread,
Aug 27, 2014, 10:54:21 PM8/27/14
to v8-u...@googlegroups.com
Which distro are you using? Which make arguments are you using?

When I build on ubuntu 14.04 i386, I get a 7.7MB binary with my code
linked and a 19kB startup script embedded as a string. D8 is 7.8MB.

On OSX 10.9 (x64), I get 9.8MB. D8 is 9.8MB.

On ubuntu 14.04 (x64), I get 8.2MB. D8 is 8.2MB.

I build with:

make builddeps && make $ARCH.release i18nsupport=off
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Louis Santillan

unread,
Aug 27, 2014, 10:59:08 PM8/27/14
to v8-u...@googlegroups.com
Also, I believe when I switched from SpiderMonkey to v8 in 2008/2009,
my original builds were 3.5MB or so. Larger than SpiderMonkey at the
time.

Ben Noordhuis

unread,
Aug 28, 2014, 6:23:19 AM8/28/14
to v8-u...@googlegroups.com
On Thu, Aug 28, 2014 at 2:38 AM, Matt Kline <slav...@gmail.com> wrote:
> On Linux, I get an approximately 20 MB executable given the default flags.
> Is this about as small as V8 can be expected to get? Besides -Os, are there
> other flags I can provide or features I can disable in order to get a
> smaller size? V8 is being used to parse PAC scripts in this scenario, so it
> is assumed that the JavaScript files will be pretty small and execution
> speed isn't critical.

It sounds like the binary isn't stripped and that V8 is linked against
ICU. Run `strip path/to/d8` to strip debug symbols. `make
i18nsupport=off` builds without ICU.

Building without a snapshot of the run-time (`snapshot=off`) should
further reduce the binary, at the cost of slower start-up times. It
probably saves a few 100 kB at best, though.

Matt Kline

unread,
Aug 28, 2014, 1:30:44 PM8/28/14
to v8-u...@googlegroups.com
Thank you! By disabling i18n and stripping it, I was able to get the build down to 2.8 MB. This is excellent.

Now, how would I pull a similar stunt on Windows? As mentioned previously, I was able to reduce v8_base.lib to about 38 MB by setting "Debug Information Format" to "None" and optimization flags to "Minimum Size" (/O1) and "Favor small code" (/Os), but that's still massive, and that's just one of the files.

Louis Santillan

unread,
Aug 28, 2014, 2:34:31 PM8/28/14
to v8-u...@googlegroups.com
I am not sure why you need a smaller binary. 2.8MB is very good for
how much functionality is now in a modern JS engine. There are other
options as well, tiny-js [0], 42tiny-js [1], Espruino [2] and more if
you look hard enough. What size are you looking to get to or what's
your use case? There's also utilities like UPX [3].

[0] https://code.google.com/p/tiny-js/
[1] https://code.google.com/p/42tiny-js/
[2] http://www.espruino.com/
[3] http://upx.sourceforge.net/

Matt Kline

unread,
Aug 28, 2014, 2:51:37 PM8/28/14
to v8-u...@googlegroups.com
2.8 megabytes is wonderful. If you'll read my last message again, I was asking how to get similar sizes on Windows, as the default build is around 180 MB in size and I was only able to reduce it to the 40 MB range with my somewhat limited fiddling.

Ben Noordhuis

unread,
Aug 28, 2014, 2:52:44 PM8/28/14
to v8-u...@googlegroups.com
On Thu, Aug 28, 2014 at 7:30 PM, Matt Kline <slav...@gmail.com> wrote:
> Thank you! By disabling i18n and stripping it, I was able to get the build
> down to 2.8 MB. This is excellent.
>
> Now, how would I pull a similar stunt on Windows? As mentioned previously, I
> was able to reduce v8_base.lib to about 38 MB by setting "Debug Information
> Format" to "None" and optimization flags to "Minimum Size" (/O1) and "Favor
> small code" (/Os), but that's still massive, and that's just one of the
> files.

I'm not sure if you should be looking at the *.lib file, it probably
contains a lot of metadata that doesn't end up in the final
executable. How big is a statically linked d8.exe?

Matt Kline

unread,
Aug 28, 2014, 6:04:57 PM8/28/14
to v8-u...@googlegroups.com
d8 comes out to about 4 MB, so the final executable size should be fine. The .lib size is somewhat important, however, as the powers that be have decided that the .lib files will be placed in the Git repo of the project using them. Because Git handles large files rather poorly, and because Github (who we are using for hosting) places restrictions on file size, I would like to make the .lib files as small as possible too.

Yang Guo

unread,
Sep 4, 2014, 3:54:27 AM9/4/14
to v8-u...@googlegroups.com
You might be able to shave off another couple of kilobytes by using the interpreted regexp engine by compiling with regexp=interpreted. If you use V8 3.25 or older, you may also remove the debugger by debuggersupport=off. Older V8 would also have fewer features, thereby reducing the binary size. Notable features are ES6 language features and Turbo-fan, the new compiler which is not even used by default at the moment.

Yang

Carl Wang

unread,
Dec 2, 2016, 5:20:35 AM12/2/16
to v8-users
Hi Matt,

I was trying to make a v8 build(actually i need node, but node currently based on v8), and also need a small size, you said that you finally got 2.8 Mb, could you please tell me the detail of how to implement this?

Thanks
Carl

在 2014年8月29日星期五 UTC+8上午1:30:44,Matt Kline写道:

Anurag Vohra

unread,
Apr 7, 2021, 6:30:45 AM4/7/21
to v8-users
Can any one please suggest me how to get V8 of 3 MB size?
As if I follow the official guide, my output are pretty big of 28 MB !
Reply all
Reply to author
Forward
0 new messages