Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
textToPoints
is known to be sort of slow because getting relatively even sampling in Cartesian space along a Bezier curve isn't computationally easy to do. The main change here is that I've replaced the implementation we currently have with one I've been working on on the side for a while.I was using this test case to measure performance:
On p5 1.x, this would give me 15fps on my 2021 M1 Macbook Pro. After these changes, this test case runs at 60fps.
To test the speedup, I increased the sampling density until it went back down to 15fps. I found I had to crank the density up to 70 to hit the same speed as before, so this seems to be a 350% speedup on this test case.
Under the hood, the main difference is that rather than using iteration to narrow down on the point at a given length for every sample, we can, upfront, calculate a much smaller number of coarse samples at evenly spaced intervals, and then essentially use these as a skip list to quickly narrow down on the target point.
The other update here is that I've reverted the default
sampleFactor
value to what it is in 1.x (I didn't realize before that this was an existing API -- the small adjustment I made to the defaults earlier isn't important enough to warrant a breaking change.)