Skip to content

Commit

Permalink
Lower initial memory, with runtime config to set higher (#164)
Browse files Browse the repository at this point in the history
Allow setting higher initial memory than that set at compile time
  • Loading branch information
samwillis authored Aug 11, 2024
1 parent c6d7913 commit 386cdb9
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cibuild/linkexport.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion cibuild/linkweb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion cibuild/pgbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions packages/pglite/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface PGliteOptions {
relaxedDurability?: boolean
extensions?: Extensions
loadDataDir?: Blob | File
initialMemory?: number
}

export type PGliteInterface = {
Expand Down
1 change: 1 addition & 0 deletions packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class PGlite implements PGliteInterface, AsyncDisposable {
let emscriptenOpts: Partial<PostgresMod> = {
WASM_PREFIX,
arguments: args,
INITIAL_MEMORY: options.initialMemory,
noExitRuntime: true,
...(this.debug > 0
? { print: console.info, printErr: console.error }
Expand Down
1 change: 1 addition & 0 deletions packages/pglite/src/postgresMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface PostgresMod
postRun: Array<{ (mod: PostgresMod): void }>
FS: FS
WASM_PREFIX: string
INITIAL_MEMORY: number
pg_extensions: Record<string, Promise<Blob | null>>
_pg_initdb: () => number
_interactive_write: (msgLength: number) => void
Expand Down

1 comment on commit 386cdb9

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.