v8.lib size of 100 MB issue and execution time while not compiling same as when compiling

182 views
Skip to first unread message

Philippe Roy

unread,
Jan 4, 2010, 12:50:31 PM1/4/10
to v8-users
I am almost ready to post an article that partly uses Google v8, and I
must say that Google v8 does not shine as much as I would want to in
it.

The complete article is available here while I am working on the
details: http://www.conceptualspeech.com/DigitalConceptBuilder_article/DigitalConceptBuilder.html

Here are my concerns that I would appreciate fixed prior to the final
submission (which I would want to happen next week).

1) v8.lib is 100 MB... That is absolutely not reasonable. I am under
Win 32. I need some help in order to find a way to bring this to a
reasonable level for distribution without requiring people to install
v8's code and Python and scons is at all possible.

2) My pick of Google v8 was partially motivated by the statements that
it is the fastest Javascript engine around. I am not convinced of that
statement anymore. The execution of my code spends exactly the same
amount of time if it compiles the Javascript repeatedly versus if it
grabs the compiled Javascript from a cache. That is extremely
surprising to me. The source code is available from the URL specified.
If referring to ExecuteJavascriptString in JSObjectSupport.cpp, the
area to investigate would be there.

Handle<Value> ExecuteJavascriptString(Persistent<Context> context,
string dSourceStr, string nameStr, bool skiptrace, Handle<Script>
*dScript) throw(CMathematicalError)
{
Context::Scope context_scope(context);

Handle<Value> result;
Handle<String> source = String::New(dSourceStr.c_str());
Handle<Script> script;
if (dScript == NULL)
{
Handle<Value> name = String::New(nameStr.c_str());
{
TryCatch try_catch;
script = Script::Compile(source, name);
if (script.IsEmpty())
{
String::AsciiValue error(try_catch.Exception());
string tmpString = *error;
throw(new CMathematicalError(tmpString));
}
}
}
else
{
script = *dScript;
}
...
}

If the test "if (dScript == NULL)" is changed to "if (true)" then we
bypass the cache. You should see that by doing that, there was close
to no changes in the time spent calculating. That is extremely
surprising as Javascript files are compiled many times for each test-
case.

If someone could help me realign my expectations or make the code
changes in order to reach my expectations, I would appreciate the
help.

Thank you.

Stephan Beal

unread,
Jan 4, 2010, 1:36:59 PM1/4/10
to v8-u...@googlegroups.com
On Mon, Jan 4, 2010 at 6:50 PM, Philippe Roy <pr...@conceptualspeech.com> wrote:
1) v8.lib is 100 MB... That is absolutely not reasonable. I am under
Win 32.

This is a common complaint (check the list archives), and the problem is not v8, but the build environment and compilation flags. On my box, libv8 is 2.4MB (32bit) or about 10x that size for the debug lib.
  
2) My pick of Google v8 was partially motivated by the statements that
it is the fastest Javascript engine around.

i don't think anyone's claimed that v8 COMPILES the fastest (your demo is compile-heavy but execution-light, AFAICS). i think the speed comparisons which have been made measured in terms of JS runtime speed, not JS compile time speed. In my (simplified) tests, comparing v8 to SpiderMonkey, v8 calls functions about 200x(!!!) faster than SpiderMonkey. While no scripting language will ever be as fast or memory-light as a compiled language, v8 is fast for a JS engine.


PS: if you're really throwing exceptions by pointer, instead of const reference, you REALLY should pick up a copy of Scott Meyers' "Effective C++".

--
----- stephan beal
http://wanderinghorse.net/home/stephan/

Stephan Beal

unread,
Jan 4, 2010, 1:40:06 PM1/4/10
to v8-u...@googlegroups.com
On Mon, Jan 4, 2010 at 7:36 PM, Stephan Beal <sgb...@googlemail.com> wrote:
PS: if you're really throwing exceptions by pointer, instead of const reference, you REALLY should pick up a copy of Scott Meyers' "Effective C++".

Sorry, that's covered in "More Effective C++", not "Effective C++", Item #13.

Abdulla Kamar

unread,
Jan 4, 2010, 3:14:30 PM1/4/10
to v8-u...@googlegroups.com
I believe that's throw by value, catch by reference. I don't remember it ever being const reference. Having said that, it looks like Philippe is coming from a Java or C# background, so it's an understandable mistake.




--
Thank you
Abdulla

Philippe Roy

unread,
Jan 4, 2010, 7:28:30 PM1/4/10
to v8-u...@googlegroups.com
You guys are absolutely right... There was a memory leak there and it
is not clean to do so. I have fixed it.

Rest assure that I appreciate any constructive feedback such as the
ones that were communicated so far.

I will dig to see how scons work so that I could get my lib to a
reasonable size. If anyone has a specific posting that could easily be
referred, I would appreciate the input. I will try to find it on my
own in the meantime.

BTW, serious documentation should be made for a novice, such as
myself, and include these important details. It's a downer to have to
dig for basic information and to have to become an expert just to be a
user (I know that is part of the UNIX philosophy that everyone should
be an expert)...

Thank you

Philippe Roy

unread,
Jan 4, 2010, 7:55:09 PM1/4/10
to v8-u...@googlegroups.com
Guys,

Could any of you give me the scons command to execute to get my
compile going with Visual Studio 2008?

The command that I have used is:

cons env="PATH:C:\Program Files\Microsoft Visual Studio
9.0\VC\bin;C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio
9.0\Common7\Tools,INCLUDE:C:\Program Files\Microsoft Visual Studio
9.0\VC\include;C:\Program Files\Microsoft
SDKs\Windows\v6.0A\Include,LIB:C:\Program Files\Microsoft Visual
Studio 9.0\VC\lib;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"

That gets it to compile and as stated in this thread the file
generated is way too large. I assume the way to get a smaller file is
not to compile it as a shared library... But I could still compile a
lib that is of more reasonable size.

I have looked around for the scons instructions but failed so far.
Your help is welcome.

ionlupascu

unread,
Jan 5, 2010, 7:02:02 AM1/5/10
to v8-users
OK,

I compiled v8 and v8.lib file is 93.7Mb. It is too large.

Compilation option is:
scons env="INCLUDE:C:\Program Files\Microsoft SDKs\Windows
\v6.1\Include;C:\Program Files\Microsoft Visual Studio 9.0\VC
\include,LIB:C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib;C:


\Program Files\Microsoft Visual Studio 9.0\VC\lib"

Philippe Roy

unread,
Jan 5, 2010, 5:34:57 PM1/5/10
to v8-u...@googlegroups.com
Stephan, or somoeone else, could you send me the latest compiled lib?
I do not find the instructions to get it to a reasonable size and
really do not have much energy to get deeper into this issue.

Thank you.

Stephan Beal

unread,
Jan 5, 2010, 10:59:15 PM1/5/10
to v8-u...@googlegroups.com
On Tue, Jan 5, 2010 at 11:34 PM, Philippe Roy <pr...@conceptualspeech.com> wrote:
Stephan, or somoeone else, could you send me the latest compiled lib?

It won't do you any good - i'm on Linux.

I do not find the instructions to get it to a reasonable size and
really do not have much energy to get deeper into this issue.

Check out the archives of this list - this topic has been brought up several times before.

Philippe Roy

unread,
Jan 5, 2010, 11:26:07 PM1/5/10
to v8-u...@googlegroups.com
I agree with you the topic has been brought many times, but at no
point to my knowledge it is written clearly "Here's the solution". And
by the solution, I mean here's the scons command for Visual Studio
2008 that will build you the library file that is reasonable in size.
Everywhere you have instances of try this, and try that... A serious
board that has for mission to really give a sense of community and be
goal oriented should be able to point to me to the exact solution
instead of having to back-track and try everything that was
communicated to try over the years.

Come on guys, I know someone has the solution... Throw it at me so
that I can go back to my 3 kids and play with them...

Stephan Beal

unread,
Jan 5, 2010, 11:45:58 PM1/5/10
to v8-u...@googlegroups.com
On Wed, Jan 6, 2010 at 5:26 AM, Philippe Roy <pr...@conceptualspeech.com> wrote:
I agree with you the topic has been brought many times, but at no
point to my knowledge it is written clearly "Here's the solution".

Good luck finding any such docs for v8. i, as a standalone developer, write more documentation for my projects than the v8 team can seem to conjure up for v8. It's not my intention to flame the developers, but documenting code is a fundamental part of writing the code (they go hand in hand, IMO), and for all of v8's technical merits, documentation is not one of v8's merits.

And
by the solution, I mean here's the scons command for Visual Studio
2008 that will build you the library file that is reasonable in size.

i don't use Windows (except to play Starwars Battlefront), so i can't help you out with that - i can only say that i've seen it brought up on this list before.
 
Come on guys, I know someone has the solution... Throw it at me so
that I can go back to my 3 kids and play with them...

i feel for you - i've spent hundreds of hours hacking on v8-based code, and many dozens of those hours have been spent trying to figure out how v8 really works (i.e. painful trial and error), since so much of the documentation is either missing or so minimal as to be useless. (i'm still wondering what API docs like "starts preemption" are trying to tell me.) Adequately documented software projects (libQt comes to mind) are unfortunately few and far between.

Philippe Roy

unread,
Jan 6, 2010, 7:35:00 AM1/6/10
to v8-u...@googlegroups.com
Thank you Stephan. You are a gentleman and I concur with your views on
documentation. I think that Google should show some leadership on such
issue. After all, their name is behind it...

So far, the command...

scons mode=release library=shared env="PATH:C:\Program Files\Microsoft


Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio
9.0\Common7\Tools,INCLUDE:C:\Program Files\Microsoft Visual Studio
9.0\VC\include;C:\Program Files\Microsoft
SDKs\Windows\v6.0A\Include,LIB:C:\Program Files\Microsoft Visual
Studio 9.0\VC\lib;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib"

...build v8.lib (187K) and v8.dll (1.41MB) but results in these 2
linking errors in the code:

Error 1 error LNK2001: unresolved external symbol "public: static int
v8::internal::Internals::kJSObjectType"
(?kJSObjectType@Internals@internal@v8@@2HA) JSObjectSupport.obj DigitalConceptBuilder
Error 2 error LNK2001: unresolved external symbol "public: static int
v8::internal::Internals::kFirstNonstringType"
(?kFirstNonstringType@Internals@internal@v8@@2HA) Predicate.obj DigitalConceptBuilder

I am wondering if a recent add by someone which may have forgotten to
update the build file may be the cause of that.

Should I be able to get around these 2 linking errors, I would be in business.

Thank you

Philippe Roy

unread,
Jan 6, 2010, 8:47:59 PM1/6/10
to v8-u...@googlegroups.com
OK, I finally got v8 to work and the lib to a reasonable size. For the
records, the lib file generated while creating the dll is the one to
use. It is about 180 K in size. Then, one has to recompile the program
that uses v8 with the preprocessor option USING_V8_SHARED and add the
lib file to the project. Then, you need to ensure that v8.dll is in
the working directory at startup.

krovosos

unread,
Jan 7, 2010, 11:38:37 AM1/7/10
to v8-users
You can use msvcltcg=off option to reduce v8.lib size to ~ 25 Mb:

scons msvcltcg=off mode=release library=static snapshot=on ...

I haven't noticed serious performance degradation without Link Time
Code Generation.

[...]

Jens Alfke

unread,
Jan 7, 2010, 12:22:22 PM1/7/10
to v8-u...@googlegroups.com

On Jan 6, 2010, at 5:47 PM, Philippe Roy wrote:

> OK, I finally got v8 to work and the lib to a reasonable size. For the
> records, the lib file generated while creating the dll is the one to
> use. It is about 180 K in size. Then, one has to recompile the program
> that uses v8 with the preprocessor option USING_V8_SHARED and add the
> lib file to the project. Then, you need to ensure that v8.dll is in
> the working directory at startup.

Cool! So now, in the spirit of open source, you are going to add the
documentation on how to do this to the wiki, right? :)

—Jens

Søren Gjesse

unread,
Jan 11, 2010, 5:26:12 AM1/11/10
to v8-u...@googlegroups.com
The size of the v8.lib file is not really important, what matters is the size of the resulting executable (either the program statically linked with v8.lib or the generated v8.dll when using a shared library). With Visual C++ 2008 (both Express and Retail) v8.lib ends up at almost 100MB when build on its own. It is 25MB with mscvltcg=off and about 30MB for the debug version. However when the sample shell is build and statically linked to V8 the resulting executable is about 1.3 MB (a bit larger when mscvltcg=off is used).

Regards,
Søren

Philippe Roy

unread,
Jan 11, 2010, 1:00:18 PM1/11/10
to v8-u...@googlegroups.com
Soren,

Somtimes, size does matter... I was working on an article that shows
how to perform conceptual analysis from textual input (that uses v8).
In order to post an article with a reasonable download size, I could
not integrate a 100 MB download into it. I fixed the issue by
compiling the shared library and taking the lib that resulted from
that compile instead.

BTW, the article in question is here:
http://www.codeproject.com/KB/recipes/DigitalConceptBuilder.aspx. It
does some pretty neat stuff with v8 and defines some nice artificial
intelligence tricks to deal with language to produce and manipulate
concepts.

Thank you.

Philippe Roy

2010/1/11 Søren Gjesse <sgj...@chromium.org>:

Reply all
Reply to author
Forward
0 new messages