I filed an issue against emscripten to be more efficient with
zero-initialized values in the .mem file:
https://github.com/kripken/emscripten/issues/3907

On Mon, Nov 9, 2015 at 3:35 PM Dan Vanderkam <dan...@gmail.com> wrote:

> Aha! This was the culprit:
>
> @localVar = global [16 x %struct.localVarType] zeroinitializer, align 8
>
> sizeof(localVarType) = 1688368 (~1.6MB), so this accounts for the lion's
> share of the memory. The 16 is a max_threads constant, so if I change that
> to 1 (I assume asm.js code is single-threaded?) and allocate the local var
> dynamically, I should get a much lighter .mem file.
>
> Thanks for the help,
>   - Dan
>
> On Mon, Nov 9, 2015 at 3:26 PM Dan Vanderkam <dan...@gmail.com> wrote:
>
>> Using llvm-dis, I can see some of the zero-initialized global symbols:
>>
>> $ /usr/local/Cellar/emscripten/1.33.0/libexec/llvm/bin/llvm-dis out.bc
>> $ grep 'zeroinitializer' out.ll
>> @relRank = global [8192 x [15 x i8]] zeroinitializer, align 1  // ~122k
>> @winRanks = global [8192 x [14 x i16]] zeroinitializer, align 2  // ~229k
>> @groupData = global [8192 x %struct.moveGroupType] zeroinitializer, align
>> 4  // ~950k
>> @maskBytes = global [8192 x [4 x [4 x i32]]] zeroinitializer, align 4 //
>> ~524k
>>
>> ...
>> %struct.moveGroupType = type { i32, [7 x i32], [7 x i32], [7 x i32], [7 x
>> i32] }
>>
>> Those were the largest symbols by far but, combined, they only account
>> for ~2MB of zeros. It would be nice if llvm-dis (or llvm-nm) could just
>> print out the total size of each of these!
>>
>> On Mon, Nov 9, 2015 at 2:58 PM Jukka Jylänki <juj...@gmail.com> wrote:
>>
>>> Oh sorry, ignore the above, gmail was not showing the rest of the
>>> communication, I see now that you got further in diagnosing.
>>>
>>> 2015-11-09 21:57 GMT+02:00 Jukka Jylänki <juj...@gmail.com>:
>>>
>>>> Yes, try the version of llvm-nm that is part of the Emscripten fork of
>>>> LLVM. (emsdk/clang/fastcomp/build_incoming_64/bin/llvm-nm).
>>>>
>>>> 2015-11-09 18:51 GMT+02:00 Dan Vanderkam <dan...@gmail.com>:
>>>>
>>>>> Do I need to use a special version of llvm-nm?
>>>>>
>>>>> $ emcc --closure 1 -s TOTAL_MEMORY=$((256 * 1024 * 1024)) -O2 dds.cpp
>>>>> ABsearch.cpp ABstats.cpp CalcTables.cpp DealerPar.cpp Init.cpp
>>>>> LaterTricks.cpp Moves.cpp Par.cpp PlayAnalyser.cpp PBN.cpp QuickTricks.cpp
>>>>> Scheduler.cpp SolveBoard.cpp SolverIF.cpp Stats.cpp Timer.cpp
>>>>> TransTable.cpp next-plays.cc *-o out.bc* -s
>>>>> EXPORTED_FUNCTIONS="['_solve']"
>>>>> $ brew install llvm
>>>>> $ /usr/local/opt/llvm/bin/llvm-nm out.bc
>>>>> error: Invalid record
>>>>>
>>>>> On Mon, Nov 9, 2015 at 11:23 AM Jukka Jylänki <juj...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> If I remember correctly, llvm-nm should show the data sizes as well?
>>>>>> Try doing "-o out.bc", and llvm-nm on the out.bc file.
>>>>>>
>>>>>> 2015-11-09 18:14 GMT+02:00 Dan Vanderkam <dan...@gmail.com>:
>>>>>>
>>>>>>> I've had good luck getting dds-bridge
>>>>>>> <https://github.com/dds-bridge/dds> to build using emscripten. I
>>>>>>> can run it in the browser just great.
>>>>>>>
>>>>>>> My main issue is that emcc generates a 28MB .mem file which it has
>>>>>>> to load via XHR to initialize. Based on how well this file gzips
>>>>>>> (28MB→30k), I suspect that it consists almost entirely of zeros. How 
>>>>>>> can I
>>>>>>> debug why such a large file is being generated? The equivalent 
>>>>>>> executable
>>>>>>> built with g++ is only ~86k.
>>>>>>>
>>>>>>> Here are steps to repro:
>>>>>>>
>>>>>>> $ git clone https://github.com/danvk/dds.git
>>>>>>> $ cd dds/src
>>>>>>> $ emcc --closure 1 -s TOTAL_MEMORY=$((256 * 1024 * 1024)) -O2
>>>>>>> dds.cpp ABsearch.cpp ABstats.cpp CalcTables.cpp DealerPar.cpp Init.cpp
>>>>>>> LaterTricks.cpp Moves.cpp Par.cpp PlayAnalyser.cpp PBN.cpp 
>>>>>>> QuickTricks.cpp
>>>>>>> Scheduler.cpp SolveBoard.cpp SolverIF.cpp Stats.cpp Timer.cpp
>>>>>>> TransTable.cpp next-plays.cc -o out.html -s 
>>>>>>> EXPORTED_FUNCTIONS="['_solve']"
>>>>>>> $ ls -lh out*
>>>>>>>   101K out.html
>>>>>>>    28M out.html.mem
>>>>>>>   320K out.js
>>>>>>> $ gzip -c out.html.mem | wc -c
>>>>>>>    31098
>>>>>>>
>>>>>>> Thanks for such an amazing tool!
>>>>>>>
>>>>>>>   - Dan
>>>>>>>
>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "emscripten-discuss" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>> send an email to emscripten-discuss+unsubscr...@googlegroups.com.
>>>>>>
>>>>>>
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to a topic in
>>>>>> the Google Groups "emscripten-discuss" group.
>>>>>> To unsubscribe from this topic, visit
>>>>>> https://groups.google.com/d/topic/emscripten-discuss/nZz2tjepBPY/unsubscribe
>>>>>> .
>>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>>> emscripten-discuss+unsubscr...@googlegroups.com.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "emscripten-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to emscripten-discuss+unsubscr...@googlegroups.com.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "emscripten-discuss" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/emscripten-discuss/nZz2tjepBPY/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> emscripten-discuss+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to