wasm: set ALLOW_MEMORY_GROWTH for multi-threaded builds

Unify the settings for single-threaded and multi-threaded builds;
Qt now always enables heap growth by default.

This means we don't have to reserve a large (1GB) fixed memory
size, but can instead set the smaller (50 MB) initial memory size,
like the single-threaded build does.

Enabling threads + memory growth can potentially cause
a performance regression when accessing heap memory from
JavaScript (https://github.com/WebAssembly/design/issues/1271).
We leave it for the application to decide if this applies,
and if the switch to fixed memory should be made.

Change-Id: I96988b072506456685086e55aca4007a146bd70f
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Morten Sørvig 2022-08-26 09:49:52 +02:00
parent 50b05e3e2a
commit df76a0585f
3 changed files with 8 additions and 36 deletions

View File

@ -35,10 +35,10 @@ function (qt_internal_setup_wasm_target_properties wasmTarget)
if (QT_FEATURE_thread)
target_compile_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
target_link_options("${wasmTarget}" INTERFACE "SHELL:-pthread")
else()
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH=1")
endif()
target_link_options("${wasmTarget}" INTERFACE "SHELL:-s ALLOW_MEMORY_GROWTH")
# debug add_compile_options
if ("QT_WASM_SOURCE_MAP=1" IN_LIST QT_QMAKE_DEVICE_OPTIONS)
set(WASM_SOURCE_MAP_BASE "http://localhost:8000/")

View File

@ -29,29 +29,16 @@ exists($$QMAKE_QT_CONFIG) {
message("Setting PTHREAD_POOL_SIZE to" $$POOL_SIZE)
EMCC_LFLAGS += -s PTHREAD_POOL_SIZE=$$POOL_SIZE
} else {
EMCC_LFLAGS += -s ALLOW_MEMORY_GROWTH=1
}
# Set memory options
EMCC_LFLAGS += -sALLOW_MEMORY_GROWTH
isEmpty(QT_WASM_INITIAL_MEMORY) {
# Hardcode wasm memory size.
qtConfig(thread) {
# Pthreads and ALLOW_MEMORY_GROWTH can cause javascript wasm memory access to
# be slow. Instead, we specify the memory size
# at build time. Further, browsers limit the maximum initial memory size to 1GB.
# https://github.com/WebAssembly/design/issues/1271
INITIAL_MEMORY = 1GB
} else {
INITIAL_MEMORY = 50MB # emscripten default is 16MB, we need slightly more
}
INITIAL_MEMORY = 50MB # emscripten default is 16MB, we need slightly more
} else {
# QT_WASM_INITIAL_MEMORY must be a multiple of 64KB (i.e. 65536)
INITIAL_MEMORY = $$QT_WASM_INITIAL_MEMORY
message("Setting INITIAL_MEMORY to" $$INITIAL_MEMORY)
}
EMCC_LFLAGS += -s INITIAL_MEMORY=$$INITIAL_MEMORY
message("Setting INITIAL_MEMORY to" $$INITIAL_MEMORY)
qtConfig(sse2) {
QMAKE_CFLAGS += -O2 -msimd128 -msse -msse2

View File

@ -48,29 +48,14 @@ function(_qt_internal_wasm_add_target_helpers target)
message(DEBUG "Setting PTHREAD_POOL_SIZE to ${POOL_SIZE} for ${target}")
endif()
# Hardcode wasm memory size.
# Set initial memory size, either from user setting or to a minimum amount required by Qt.
get_target_property(_tmp_initialMemory "${target}" QT_WASM_INITIAL_MEMORY)
if(_tmp_initialMemory)
set(QT_WASM_INITIAL_MEMORY "${_tmp_initialMemory}")
elseif(NOT DEFINED QT_WASM_INITIAL_MEMORY)
if(QT_FEATURE_thread)
# Pthreads and ALLOW_MEMORY_GROWTH can cause javascript wasm memory access to
# be slow and having to update HEAP* views. Instead, we specify the memory size
# at build time. Further, browsers limit the maximum initial memory size to 1GB.
# https://github.com/WebAssembly/design/issues/1271
set(QT_WASM_INITIAL_MEMORY "1GB")
else()
# emscripten default is 16MB, we need slightly more sometimes
set(QT_WASM_INITIAL_MEMORY "50MB")
endif()
endif()
if(DEFINED QT_WASM_INITIAL_MEMORY)
# QT_WASM_INITIAL_MEMORY must be a multiple of 65536
target_link_options("${target}"
PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
message(DEBUG "-- Setting INITIAL_MEMORY to ${QT_WASM_INITIAL_MEMORY} for ${target}")
set(QT_WASM_INITIAL_MEMORY "50MB")
endif()
target_link_options("${target}" PRIVATE "SHELL:-s INITIAL_MEMORY=${QT_WASM_INITIAL_MEMORY}")
endif()
endfunction()