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

Struct-valued custom enumerator for pixel offsets #1171

Merged
merged 7 commits into from
Dec 23, 2024

Conversation

Lehonti
Copy link
Contributor

@Lehonti Lehonti commented Nov 30, 2024

I think one shouldn't have to allocate on the heap in order to enumerate the pixel coordinates and offsets.

To be consumed by a foreach loop an object doesn't need to implement IEnumerable<T>, but only expose public methods with the corresponding names and signatures.

It is my understanding that this new approach would prevent heap allocations except when the object is explicitly used as an IEnumerable<T> (like in VoronoiDiagramEffect through an invocation of Select).

@Lehonti Lehonti marked this pull request as ready for review November 30, 2024 03:03
@cameronwhite
Copy link
Member

Could you try running the effect benchmarks to see if there's a notable difference with this change? If so I'm okay with it, but otherwise the original implementation is much simpler

@cameronwhite
Copy link
Member

Getting back to this, I ran the benchmarks myself and there is some improvement to the overall performance, so I'm okay with the change since it's a core utility used by many effects.
Could you just add some doc comments to the new classes to explain their purpose?

Before:

| Method      | Mean     | Error   | StdDev  | Allocated |
|------------ |---------:|--------:|--------:|----------:|
| BulgeEffect | 208.1 ms | 1.67 ms | 1.39 ms |   1.14 KB |

After:

| Method      | Mean     | Error   | StdDev  | Allocated |
|------------ |---------:|--------:|--------:|----------:|
| BulgeEffect | 196.3 ms | 2.38 ms | 2.23 ms |   1.04 KB |

@Lehonti
Copy link
Contributor Author

Lehonti commented Dec 23, 2024

Thank you for running the benchmarks, @cameronwhite! I had tried to run them but ran into problems when NUnit refused to do it because they referenced an unoptimized library from Mono, and since these last few weeks have been busy I didn't have the time to figure out what the problem was.

I just added documentation comments to the new structs

@cameronwhite
Copy link
Member

No problem - I committed e2cba39 which works around those errors running the benchmarks

@cameronwhite cameronwhite merged commit bd4b3be into PintaProject:master Dec 23, 2024
5 checks passed
@Lehonti Lehonti deleted the improvement7 branch December 23, 2024 18:11
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

Successfully merging this pull request may close these issues.

2 participants