Comments (3)
It looks like you initialize wasm-vips on every createMultiPageImage()
call. I would initialize wasm-vips only once and reuse its instance. For example:
Details
--- a/handle-multi-image.mjs
+++ b/handle-multi-image.mjs
@@ -12,6 +12,10 @@ function log(msg) {
console.log(msg, "\n" + JSON.stringify(obj, null, 4) + "\n");
}
+const vips = await Vips();
+vips.concurrency(1);
+vips.Cache.max(0);
+
async function createMultiPageImage(buffer, op, ...params) {
const buffers = [];
const { pages: pageCount } = await sharp(buffer, { pages: -1 }).metadata();
@@ -31,10 +35,6 @@ async function createMultiPageImage(buffer, op, ...params) {
}
}
- const vips = await Vips();
- vips.concurrency(1);
- vips.Cache.max(0);
-
const vipsPages = pages.map((page) => vips.Image.newFromBuffer(page, "", { access: vips.Access.sequential }));
const vipsImage = vips.Image.arrayjoin(vipsPages, { across: 1 });
@@ -44,7 +44,6 @@ async function createMultiPageImage(buffer, op, ...params) {
vipsPages.map((vipsPage) => vipsPage.delete());
vipsImage.delete();
- vips.shutdown();
return Buffer.from(vipsBuffer);
}
With that, I see:
flop
{
"rss": 123,
"heapTotal": 31,
"heapUsed": 13,
"external": 7,
"arrayBuffers": 5
}
negate
{
"rss": 125,
"heapTotal": 31,
"heapUsed": 13,
"external": 7,
"arrayBuffers": 5
}
flip
{
"rss": 242,
"heapTotal": 31,
"heapUsed": 14,
"external": 9,
"arrayBuffers": 7
}
rotate
{
"rss": 263,
"heapTotal": 31,
"heapUsed": 14,
"external": 14,
"arrayBuffers": 11
}
trim
{
"rss": 275,
"heapTotal": 31,
"heapUsed": 14,
"external": 19,
"arrayBuffers": 16
}
Which is probably reasonable for image processing in WebAssembly.
from wasm-vips.
Just implemented the above logic and working flawlessly. Apart from the initial memory jump, all other subsequent vips calls are within constraint. Thank you @kleisauke for the fix and also for the amazing package. ππΎββοΈ
from wasm-vips.
This definitely looks promising. Currently busy with work, but will definitely check this out and revert back. Thank you for checking the issue. ππΎ
from wasm-vips.
Related Issues (20)
- Playground feature request: ability to import file from disk HOT 3
- `WasmTrapJSTypeError` while loading an SVG when building with LTO HOT 4
- Docker compilation error HOT 6
- setup wasm-vips for next.js/react HOT 3
- TS types improvements HOT 3
- Not working on deno deploy HOT 1
- ab [vips::Error]: no such operation pdfload_buffer VipsOperation: class "pdfload_buffer" not found HOT 1
- JPEG 2000 Support HOT 2
- Errors with vite HOT 29
- No paths work when reading files (Deno) HOT 2
- Promise remains in pending mode HOT 5
- Error `heifload: ignoring nclx profile` when converting to AVIF and resizing HOT 4
- Add progress information HOT 3
- Error: need to see wasm magic number HOT 1
- Enhancement βΒ more modular loading HOT 3
- Interlace option in jpegsaveBuffer doesnβt seem to work HOT 3
- [Question] How do you deal with CDNs and Vite HOT 2
- JPG images failing to write: writeToBuffer stalling issue HOT 11
- call of writeToBuffer on huge png causing tab freeze HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm-vips.