Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-moons-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Allow setting initial memory size.
8 changes: 8 additions & 0 deletions packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,19 @@ export class PGlite
fsBundleBuffer = buffer
})

const wasmMemory = new WebAssembly.Memory({
initial: options.initialMemory
? options.initialMemory / (64 * 1024)
: 2048,
maximum: 32768,
})

let emscriptenOpts: Partial<PostgresMod> = {
thisProgram: postgresExePath,
WASM_PREFIX,
arguments: args,
noExitRuntime: true,
wasmMemory: wasmMemory,
// Provide a stdin that returns EOF to avoid browser prompt
stdin: () => null,
print: (text: string) => {
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 @@ -22,6 +22,7 @@ export interface PostgresMod
thisProgram: string
stdin: (() => number | null) | null
FS: FS
wasmMemory: WebAssembly.Memory
PROXYFS: Emscripten.FileSystemType
WASM_PREFIX: string
pg_extensions: Record<string, Promise<Blob | null>>
Expand Down
11 changes: 11 additions & 0 deletions packages/pglite/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,16 @@ await testEsmCjsAndDTC(async (importType) => {
current_role: 'postgres',
})
})

it('initialMemory works', async () => {
const wantedMemSize = 512 * 1024 * 1024
const db = await PGlite.create({
initialMemory: wantedMemSize,
})

const instanceMemSize = db.Module.HEAPU8.buffer.byteLength

expect(instanceMemSize).toEqual(wantedMemSize)
})
})
})
2 changes: 1 addition & 1 deletion postgres-pglite
Loading