-
Notifications
You must be signed in to change notification settings - Fork 398
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
Optimise ColourInfo
conversion and add conversion helper method
#5472
Conversation
Tests not happy 😢 |
return colour.singleColour; | ||
|
||
[DoesNotReturn] | ||
static void throwConversionFromMultiColourToSingleColourException() => throw new InvalidOperationException("Attempted to read single colour from multi-colour ColourInfo."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already exists a throw helper for InvalidOperationException here.
Maybe we can use this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is supposed to be a correct use case of that method, because it causes a string construction in the conversion method, which is what's being avoided in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it's not a string construction, but rather the code constructing the string results in a lot of dead (i.e. never hit) ASM code for the JIT to compile that could also potentially cause the function to not be inlined.
Fixed tests, the assertion was added post-fact. |
The performance gains here are mostly theoretical and I can't benchmark them meaningfully in a real-world scenario. Consider this more of a refactoring that adds an optimal (and more user-friendly) method for checking whether a
ColourInfo
represents a single colour and then returning that colour.This comes off the back of the osu!-side smoke implementation (where I initially noticed this), which potentially uses this method for tens of thousands of vertices (up to 30k is what I was able to achieve after the recent changes). Similar is also done with slider paths (e.g. at some point https://osu.ppy.sh/beatmapsets/756794#osu/1605148 draws some 20k vertices). So at most you'd see ~0.2ms frametime improvement.
Before
After:
It uses concepts I've learnt over the years:
throw
are not inlined - extract these methods to promote inlining.For comparisons sake, this is the best "real-world" example I could make, by looping
TestSceneSmoke
over 30 seconds:Again, I don't think these are indicative of anything so don't put much weight to them. There's too much noise.