From fedc23ca93efb77bd2b5fbe9044465dc741d9d89 Mon Sep 17 00:00:00 2001 From: Sam Willis Date: Sun, 11 Aug 2024 18:12:16 +0100 Subject: [PATCH 1/2] wip --- cibuild/linkexport.sh | 2 +- cibuild/linkweb.sh | 2 +- cibuild/pgbuild.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cibuild/linkexport.sh b/cibuild/linkexport.sh index 1955549d..3f50e4f8 100644 --- a/cibuild/linkexport.sh +++ b/cibuild/linkexport.sh @@ -1,7 +1,7 @@ echo "============= link export : begin ===============" emcc $EMCC_WEB -fPIC -sMAIN_MODULE=1 -O0 \ -D__PYDK__=1 -DPREFIX=${PGROOT} \ - -sTOTAL_MEMORY=1GB -sSTACK_SIZE=4MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sGLOBAL_BASE=${CMA_MB}MB \ + -sTOTAL_MEMORY=256MB -sSTACK_SIZE=4MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sGLOBAL_BASE=${CMA_MB}MB \ -sERROR_ON_UNDEFINED_SYMBOLS -sASSERTIONS=0 \ -lnodefs.js -lidbfs.js \ -sEXPORTED_RUNTIME_METHODS=FS,setValue,getValue,UTF8ToString,stringToNewUTF8,stringToUTF8OnStack,ccall,cwrap,callMain \ diff --git a/cibuild/linkweb.sh b/cibuild/linkweb.sh index b0807000..866d7c1e 100755 --- a/cibuild/linkweb.sh +++ b/cibuild/linkweb.sh @@ -185,7 +185,7 @@ _________________________________________________________ emcc $EMCC_WEB $LINKER $MODULE \ - -sTOTAL_MEMORY=1GB -sSTACK_SIZE=4MB -sGLOBAL_BASE=${CMA_MB}MB \ + -sTOTAL_MEMORY=256MB -sSTACK_SIZE=4MB -sGLOBAL_BASE=${CMA_MB}MB \ -fPIC -D__PYDK__=1 -DPREFIX=${PGROOT} \ -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sERROR_ON_UNDEFINED_SYMBOLS -sASSERTIONS=0 \ -lnodefs.js -lidbfs.js \ diff --git a/cibuild/pgbuild.sh b/cibuild/pgbuild.sh index 938dfb24..85f67fa4 100644 --- a/cibuild/pgbuild.sh +++ b/cibuild/pgbuild.sh @@ -117,7 +117,7 @@ END # only required for static initdb EMCC_CFLAGS="-sERROR_ON_UNDEFINED_SYMBOLS=0 ${CC_PGLITE}" - EMCC_CFLAGS="${EMCC_CFLAGS} -sTOTAL_MEMORY=1GB -sSTACK_SIZE=5MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sGLOBAL_BASE=${CMA_MB}MB" + EMCC_CFLAGS="${EMCC_CFLAGS} -sTOTAL_MEMORY=256MB -sSTACK_SIZE=5MB -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sGLOBAL_BASE=${CMA_MB}MB" EMCC_CFLAGS="${EMCC_CFLAGS} -DPREFIX=${PGROOT}" export EMCC_CFLAGS="${EMCC_CFLAGS} -Wno-macro-redefined -Wno-unused-function" From 57ed3cf4d29bb022c42e1b086355340a1639a54d Mon Sep 17 00:00:00 2001 From: Sam Willis Date: Sun, 11 Aug 2024 19:41:10 +0100 Subject: [PATCH 2/2] Allow setting higher initial memory than that set at compile time --- packages/pglite/src/interface.ts | 1 + packages/pglite/src/pglite.ts | 1 + packages/pglite/src/postgresMod.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/pglite/src/interface.ts b/packages/pglite/src/interface.ts index fb2a21eb..44f0f28e 100644 --- a/packages/pglite/src/interface.ts +++ b/packages/pglite/src/interface.ts @@ -62,6 +62,7 @@ export interface PGliteOptions { relaxedDurability?: boolean extensions?: Extensions loadDataDir?: Blob | File + initialMemory?: number } export type PGliteInterface = { diff --git a/packages/pglite/src/pglite.ts b/packages/pglite/src/pglite.ts index 548f059a..fd59e55e 100644 --- a/packages/pglite/src/pglite.ts +++ b/packages/pglite/src/pglite.ts @@ -159,6 +159,7 @@ export class PGlite implements PGliteInterface, AsyncDisposable { let emscriptenOpts: Partial = { WASM_PREFIX, arguments: args, + INITIAL_MEMORY: options.initialMemory, noExitRuntime: true, ...(this.debug > 0 ? { print: console.info, printErr: console.error } diff --git a/packages/pglite/src/postgresMod.ts b/packages/pglite/src/postgresMod.ts index aed697bb..baf4d1ca 100644 --- a/packages/pglite/src/postgresMod.ts +++ b/packages/pglite/src/postgresMod.ts @@ -21,6 +21,7 @@ export interface PostgresMod postRun: Array<{ (mod: PostgresMod): void }> FS: FS WASM_PREFIX: string + INITIAL_MEMORY: number pg_extensions: Record> _pg_initdb: () => number _interactive_write: (msgLength: number) => void