Automattic / Automattic/node-canvas
Slow addPage
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 1.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 1
Description
ctx.addPage() very slow if some rects already drawed
## Issue
ctx.addPage() very slow if some rects already drawed. If no any drawed ctx.addPage() is quick
## Steps to Reproduce
```js
const { createCanvas } = require('canvas');
const width = 420;
const height = 297;
const ctx = createCanvas(width, height, 'pdf').getContext('2d');
const draw = () => {
console.time('draw');
for (let i = 0; i < 10000; ++i) {
const r1 = Math.random();
const r2 = Math.random();
ctx.strokeStyle = ctx.fillStyle = `rgba(${Math.floor(r1 * 255)}, ${Math.floor(r2 * 255)}, ${Math.floor(r1 * 255)}, ${r2})`;
ctx.fillRect(r1 * width, r2 * height, r1, r2);
ctx.strokeRect(r1 * width, r2 * height, r1, r2);
}
console.timeEnd('draw');
};
const addPage = () => {
console.time('addPage');
ctx.addPage();
console.timeEnd('addPage');
};
for (let i = 0; i < 3; ++i) {
draw();
addPage();
addPage();
addPage();
console.log('');
}
```
Results:
```
draw: 71.481ms
addPage: 538.003ms
addPage: 0.125ms
addPage: 0.068ms
draw: 59.522ms
addPage: 535.811ms
addPage: 0.086ms
addPage: 0.123ms
draw: 59.446ms
addPage: 538.068ms
addPage: 0.083ms
addPage: 0.127ms
```
## Your Environment
* Version of node-canvas: 2.2.0
* Environment: node 11.6.0 on Win10 Home
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.