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

PrimitiveAlgo : Optimize transformPrimitive #6037

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

danieldresser-ie
Copy link
Contributor

Applies on top of #6026.

This optimizes 3 things: added threading, moving the check for interpretation out of the inner loop, and moving the canceller out of the inner loop. In theory, we only needed to delay the threading fix out of the previous PR, but the other two require splitting into subranges anyway, so it's easiest to keep them together.

@danieldresser-ie
Copy link
Contributor Author

Oh, and some performance numbers: this is embarrassingly parallel, there's an 8X speedup in the test turning on threading. The other two fixes are minor, around 10% each after threading.

@danieldresser-ie
Copy link
Contributor Author

@johnhaddon I wasn't sure what would go wrong if I just tried to switch FreezeTransform to inherit from ObjectProcessor, so I just tried it. Everything went pretty smoothly ... except that it doesn't actually work because FreezeTransform needs to process any objects that have ancestor matches, whereas ObjectProcessor is hardcoded to affect only objects with exact matches.

Do you think it could be reasonable to allow customizing that on ObjectProcessor? Or perhaps I could just make an intermediate filter plug on FreezeTransform that returns ExactMatch whenever there's an AncestorMatch?

@johnhaddon
Copy link
Member

except that it doesn't actually work because FreezeTransform needs to process any objects that have ancestor matches

Ah, of course. Sorry, I should have anticipated that.

Do you think it could be reasonable to allow customizing that on ObjectProcessor?

What would that look like? Some sort filterMask = PathMatcher::ExactMatch constructor argument that we'd pass ExactMatch | AncestorMatch to?

Or perhaps I could just make an intermediate filter plug on FreezeTransform that returns ExactMatch whenever there's an AncestorMatch?

I'm not sure that can be made to work without modifying ObjectProcessor, since it would need to know to look at the intermediate filter and not the main one (and we can't connect something to the main one, because that is user-facing).

Looking at ObjectProcessor, there is so little involved in managing the __processedObject plug that we might as well just repeat that in FreezeTransform I reckon. I checked in SceneAlgo and as long as we use the same name for the plug, we'll still benefit from the fix for #5406.

@danieldresser-ie
Copy link
Contributor Author

Copied in the implementation of the __processedObject plug. A bit of a hasty copy/paste job, but everything seems to be working OK.

@johnhaddon
Copy link
Member

Thanks Daniel. Could you rebase this on the latest main please now that I've merged the MergeObjects PR. And while you're doing that, could you add a mention of the performance improvement in Changes.md. I also wonder if we're mimicking ObjectProcessor a bit too much - it feels like maybe just moving the hashProcessedObject/computeProcessedObject code inline into hash/compute might be a bit clearer, since we're treating the transform plug that way. Whichever you think best though...

@danieldresser-ie
Copy link
Contributor Author

Removed hashProcessedObject/computeProcessedObject - I just thought the consistency might be nice for someone comparing to other nodes, but considering this code in isolation, it's definitely nicer this way.

Squashed it and added changelog, should be ready for merge.

@johnhaddon johnhaddon marked this pull request as ready for review September 19, 2024 09:35
@johnhaddon johnhaddon merged commit a003d5d into GafferHQ:main Sep 19, 2024
5 checks passed
@johnhaddon
Copy link
Member

Rebased to fix merge conflict, added a Changes.md entry to mention cancellation support, and merged.

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