canvas
canvas copied to clipboard
rss memory huge increase since 0.1.42+ ?
Use this case
const { createCanvas } = require('@napi-rs/canvas')
async function main() {
const canvas = createCanvas(300, 320)
const ctx = canvas.getContext('2d')
ctx.lineWidth = 10
ctx.strokeStyle = '#03a9f4'
ctx.fillStyle = '#03a9f4'
ctx.strokeRect(75, 140, 150, 110)
ctx.fillRect(130, 190, 40, 60)
ctx.beginPath()
ctx.moveTo(50, 140)
ctx.lineTo(150, 60)
ctx.lineTo(250, 140)
ctx.closePath()
ctx.stroke()
await canvas.encode('png')
}
async function bench() {
console.log('before', process.memoryUsage())
for (let i = 0; i < 1000; i++) {
await main()
}
console.log('after', process.memoryUsage())
}
bench()
when using @napi-rs/[email protected]
before {
rss: 41500672,
heapTotal: 5509120,
heapUsed: 5015784,
external: 372846,
arrayBuffers: 37937
}
after {
rss: 116674560,
heapTotal: 6041600,
heapUsed: 4042200,
external: 2749665,
arrayBuffers: 10458
}
when using @napi-rs/[email protected]
before {
rss: 40894464,
heapTotal: 5509120,
heapUsed: 5015976,
external: 372846,
arrayBuffers: 37937
}
after {
rss: 358780928,
heapTotal: 6041600,
heapUsed: 4042216,
external: 2749665,
arrayBuffers: 10458
}
0.1.41
-> 0.1.42
the rss usage 200% increasement in this case
my device: Node.js v16.20.2 | Linux x86_64 GNU/Linux | AMD EPYC 7Y83 64-Core Processor | MemTotal 25339608 kB
in this case 0.1.40
~ 0.1.41
is ok, 0.1.42
~ 0.1.44
will see the increasement
Duplicate https://github.com/Brooooooklyn/canvas/issues/716