Performance difference bet autotools vs cmake based wasm

116 views
Skip to first unread message

Mahesh Velankar

unread,
Dec 29, 2021, 5:13:40 PM12/29/21
to emscripten-discuss
I am trying to build a spell check library, that is c++ code.
I am able to build it , create wasm and successfully use it in the web page.

First I tried it with auto tools (since hunspell was already built for wasm using auto tools)......I refereed to the same (hunspell-wasm) build environment and just changed the details to get my wasm..........and that worked very very well.........Speed was amazing in the web page.

Then I tried to build the same code with cmake..... as I wanted to do the whole thing by myself .... better than the above copy paste approach for future support. I thought cmake was easier to grasp than autotools,. So I followed a tutorial and successfully built the wasm. That wasm also worked

However strangely this cmake based wasm performs about 10 times slower than the autotools based built wasm. (this 10 times thing is just a guess......no measurement......but it moves with ant's speed compared to the earlier)

Can somebody give me any pointers as to where should I start looking for issues.

I know this question is not giving any details, as I do not know what should I provide.
Please let me know what details I need to provide.
Thanks in advance
-Mahesh

Brion Vibber

unread,
Dec 29, 2021, 10:03:08 PM12/29/21
to emscripten Mailing List
On Wed, Dec 29, 2021 at 2:13 PM Mahesh Velankar <mvel...@gmail.com> wrote:
First I tried it with auto tools (since hunspell was already built for wasm using auto tools)......I refereed to the same (hunspell-wasm) build environment and just changed the details to get my wasm..........and that worked very very well.........Speed was amazing in the web page.

Then I tried to build the same code with cmake..... as I wanted to do the whole thing by myself .... better than the above copy paste approach for future support. I thought cmake was easier to grasp than autotools,. So I followed a tutorial and successfully built the wasm. That wasm also worked

However strangely this cmake based wasm performs about 10 times slower than the autotools based built wasm. (this 10 times thing is just a guess......no measurement......but it moves with ant's speed compared to the earlier)

As a guess, did you not include an optimization option in the compiler flags on the CMake version?

-- brion

Mahesh Velankar

unread,
Dec 30, 2021, 5:52:07 AM12/30/21
to emscripten-discuss
Brion,
Thanks for taking time to address my question.
Where should I put that compiler flag?

This is my CMakeLists.txt file

=================================================================
cmake_minimum_required(VERSION 3.5)

#project(hello_library)
project(myspell)

############################################################
# Create a library
############################################################

#Generate the static library from the library sources
add_library(myspell STATIC•
    src/myspell.cxx
    src/dict.cxx
    src/msp.cxx
)

target_include_directories(myspell
    PUBLIC•
        ${PROJECT_SOURCE_DIR}/include
)


############################################################
# Create an executable
############################################################

# Add an executable with the above sources
add_executable(myspell-bin•
    src/main.cxx
)

# link the new myspell target with the myspell-bin target
target_link_libraries( myspell-bin
    PRIVATE•
        myspell
)
# now we rename myspell-bin executable to myspell using target properties
set_target_properties(myspell-bin
        PROPERTIES OUTPUT_NAME myspell)
=================================================================

and this is how I am building it

===============================================
#! /bin/bash
ls
rm -rf build
mkdir -p build

cd build

emcmake cmake ..
emmake make
em++ -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=33554432 -s EXPORTED_FUNCTIONS="['_Myspell_create', '_Myspell_spell', '_Myspell_suggest', '_Myspell_free_list', '_Myspell_destroy']" ./libmyspell.a -o myspell.js

cp ../myspell-worker.js .
===============================================

Please let me know where should I make the changes.
Also please let me know if I need to provide more details

Thanks
-Mahesh

On Wednesday, December 29, 2021 at 10:03:08 PM UTC-5 br..com wrote:

Mahesh Velankar

unread,
Dec 30, 2021, 8:31:16 AM12/30/21
to emscripten-discuss
I tried to find out the differences in the build step.
I removed a header file and made the build fail .... so that I could get the compiler line print out
Here is the one with autotools
=========================================
em++: error: '/home/myname/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=0 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/myname/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -DHAVE_CONFIG_H -I. -I../.. -fvisibility=hidden -DBUILDING_LIBmySPELL -g -O2 -MT myspell.lo -MD -MP -MF .deps/myspell.Tpo -c -fPIC -DPIC myspell.cxx -o .libs/myspell.o' failed (returned 1)
=========================================
Here is the one with CMake
=========================================
em++: error: '/home/myname/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=0 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/home/myname/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I/home/myname/cmake_expt/myspell/include -c /home/myname/cmake_expt/myspell/src/myspell.cxx -o CMakeFiles/myspell.dir/src/myspell.cxx.o' failed (returned 1)
=========================================
I can see the difference in the visibility setting.  Also I see there are are -g O2 -MT -MD -MP -MF -fPIC -dPIC in Autotools but not in CMake.
See if anybody could find anything from this.
Also pl tell me where to make the required change
Thanks

Floh

unread,
Dec 30, 2021, 9:51:37 AM12/30/21
to emscripten-discuss
The autotools command line has the "-O2" optimization flag, which the cmake command line is missing.

Try running emcmake like this (to enable optimizations favouring size over performance:

emcmake cmake -DCMAKE_BUILD_TYPE=MinSizeRel ..

...or this to enable optimizations favouring performance over size:

emcmake cmake -DCMAKE_BUILD_TYPE=Release ..

Mahesh Velankar

unread,
Dec 30, 2021, 10:43:40 AM12/30/21
to emscripten-discuss
Floh,

Yes.

emcmake cmake -DCMAKE_BUILD_TYPE=Release ..

That worked like a charm.
Thanks for taking time to address my question
-Mahesh
Reply all
Reply to author
Forward
0 new messages