Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for uniting multiple paths at once to improve performance #2094

Open
blayzen-w opened this issue Mar 8, 2025 · 0 comments

Comments

@blayzen-w
Copy link

blayzen-w commented Mar 8, 2025

Description/Steps to reproduce

Currently, I believe the only way to unite multiple paths is to unite them one by one into a single compounded path.

let combined = new this.paper.CompoundPath(null);
for (const item of paths) {
    combined = combined.unite(item, {insert: false});
}

However this is memory inefficient because each call to unite will clone both the item being merged and the combined compound path which contains all previous paths in it. Its not quite O(n^2) in terms of memory allocation but it is bad.

Link to reproduction test-case

The main problem that we ran into was uniting a paragraph of text that had been outlined to paths. This sketch tries to reproduce the issue by creating 100 copies of a single word. The test can take upwards of 12 seconds to run and uses around 460mb of memory.

Sketch

Expected result

I was able to modify the internal traceBoolean function to specify if it should call preparePath on the inputs. Then I added a new function called PathItem.uniteList that would call preparePath beforehand and then reuse the results for each call to traceBoolean. This was able to reduce our internal test down from 40-60 seconds to 4 seconds with a much smaller memory footprint.

The changes that were made can be found here.

Let me know if you would like to see a pull request made for this issue and I can work on getting the code cleaned up and test cases made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant