circuitpython/ports/webassembly/Makefile
Damien George 5987130afd webassembly/Makefile: Change compiler optimisation from O3 to Os.
Emscripten strongly advises the use of optimisation when compiling with
ASYNCIFY enabled.  Testing the difference betwen O3 and Os for various
configurations gives:

    flags                      firmware.wasm   micropython.js  perf
    -O3 -s ASYNCIFY            1342003          212845         0 (baseline)
    -O3 -s ASYNCIFY -s WASM=0        -         7064750         -30%
    -O3                         367131          196569         +140%
    -O3 -s WASM=0                    -         2818260         +30%
    -Os -s ASYNCIFY            1135450          213064         +40%
    -Os -s ASYNCIFY -s WASM=0        -         6239768         -30%
    -Os                         295028          196569         +180%
    -Os -s WASM=0                    -         2271358         +30%

The first row is prior to this commit.  The second and third columns show
firmware size (add them to get the total size).  The fourth column shows
the approximate change in performance compared to the baseline.  The
performance was measured using run-perfbench.py and the error was large, up
to 20%, although general trends in the change in performance could still be
seen.

In summary, using using Os instead of O3 makes it a little bit faster in
all cases, and smaller output (wasm/js) in all cases.

Signed-off-by: Damien George <damien@micropython.org>
2022-11-07 17:18:42 +11:00

60 lines
1.5 KiB
Makefile

include ../../py/mkenv.mk
CROSS = 0
QSTR_DEFS = qstrdefsport.h
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk
CC = emcc
LD = emcc
INC += -I.
INC += -I$(TOP)
INC += -I$(BUILD)
CFLAGS += -std=c99 -Wall -Werror -Wdouble-promotion -Wfloat-conversion
CFLAGS += -Os -DNDEBUG
CFLAGS += $(INC)
SRC_SHARED = $(addprefix shared/,\
runtime/interrupt_char.c \
runtime/stdout_helpers.c \
runtime/pyexec.c \
readline/readline.c \
)
SRC_C = \
main.c \
mphalport.c \
modutime.c \
SRC_QSTR += $(SRC_C) $(SRC_SHARED)
OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
JSFLAGS += -s ASYNCIFY
JSFLAGS += -s EXPORTED_FUNCTIONS="['_mp_js_init', '_mp_js_init_repl', '_mp_js_do_str', '_mp_js_process_char', '_mp_hal_get_interrupt_char', '_mp_sched_keyboard_interrupt']"
JSFLAGS += -s EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap', 'FS']"
JSFLAGS += -s --memory-init-file 0
JSFLAGS += --js-library library.js
all: $(BUILD)/micropython.js
$(BUILD)/micropython.js: $(OBJ) library.js wrapper.js
$(ECHO) "LINK $(BUILD)/firmware.js"
$(Q)emcc $(LDFLAGS) -o $(BUILD)/firmware.js $(OBJ) $(JSFLAGS)
cat wrapper.js $(BUILD)/firmware.js > $@
min: $(BUILD)/micropython.js
uglifyjs $< -c -o $(BUILD)/micropython.min.js
test: $(BUILD)/micropython.js $(TOP)/tests/run-tests.py
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && MICROPY_MICROPYTHON=../ports/webassembly/node_run.sh ./run-tests.py -j1
include $(TOP)/py/mkrules.mk