From 06f6534402e695a2a92b454a718349a1620cf036 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 27 Aug 2023 17:46:06 +0800 Subject: [PATCH] :art: Limit memory usage of PDF parsing https://github.com/siyuan-note/siyuan/pull/9051 --- kernel/model/asset_content.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/model/asset_content.go b/kernel/model/asset_content.go index cdb8fd09a..b3a8a98d9 100644 --- a/kernel/model/asset_content.go +++ b/kernel/model/asset_content.go @@ -774,6 +774,10 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) { // initialize go-pdfium with number of available cores // we fire up the complete worker pool for maximum performance cores := runtime.NumCPU() + if 4 < cores { + cores = 4 // Limit memory usage + } + pool, err := webassembly.Init(webassembly.Config{ MinIdle: cores, MaxIdle: cores, @@ -853,7 +857,7 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) { close(results) if 128 < pc.PageCount { - logging.LogInfof("convert [%s] PDF with [%d[ pages using [%d] workers took [%s]", absPath, pc.PageCount, cores, time.Since(now)) + logging.LogInfof("convert [%s] PDF with [%d] pages using [%d] workers took [%s]", absPath, pc.PageCount, cores, time.Since(now)) } // loop through ordered PDF text pages and join content for asset parse DB result