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

bezier: optimize setup of bezier curves #8528

Merged
merged 1 commit into from
Nov 22, 2024
Merged

Conversation

gulafaran
Copy link
Contributor

avoid reallocations by resizing and copy the pVec into the resized m_dPoints, reduce the amount of calculations in baking to only do it once per iteration instead of twice. precompute in getYforT and getXforT return early in getYForPoint if x is equal or below 0. and use const references where we can.

these changes we are now down to an average of "time to bake: 2.50µs."
on my machine compared to before average of "time to bake: 11.15µs"

patched

[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.92µs. Estimated average calc time: 0.10µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.65µs. Estimated average calc time: 0.07µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.53µs. Estimated average calc time: 0.07µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.48µs. Estimated average calc time: 0.08µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.57µs. Estimated average calc time: 0.04µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.33µs. Estimated average calc time: 0.07µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.36µs. Estimated average calc time: 0.02µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.36µs. Estimated average calc time: 0.04µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.52µs. Estimated average calc time: 0.07µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.33µs. Estimated average calc time: 0.07µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.45µs. Estimated average calc time: 0.06µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.34µs. Estimated average calc time: 0.06µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.34µs. Estimated average calc time: 0.05µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 2.36µs. Estimated average calc time: 0.05µs.

and unpatched

[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 46.05µs. Estimated average calc time: 0.09µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.60µs. Estimated average calc time: 0.05µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.24µs. Estimated average calc time: 0.06µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.18µs. Estimated average calc time: 0.06µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.19µs. Estimated average calc time: 0.03µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.20µs. Estimated average calc time: 0.06µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.22µs. Estimated average calc time: 0.02µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.14µs. Estimated average calc time: 0.05µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.17µs. Estimated average calc time: 0.07µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.14µs. Estimated average calc time: 0.06µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.20µs. Estimated average calc time: 0.05µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 11.18µs. Estimated average calc time: 0.05µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 10.65µs. Estimated average calc time: 0.05µs.
[LOG] Created a bezier curve, baked 255 points, mem usage: 4.08kB, time to bake: 13.77µs. Estimated average calc time: 0.08µs.

avoid reallocations by resizing and copy the pVec into the resized
m_dPoints, reduce the amount of calculations in baking to only do it
once per iteration instead of twice. precompute in getYforT and getXforT
return early in getYForPoint if x is equal or below 0. and use const
references where we can.

these changes we are now down to an average of "time to bake: 2.50µs."
on my machine compared to before average of "time to bake: 11.15µs"
@leiserfg
Copy link
Contributor

@gulafaran, is it worthy to replace float with float const&? Aren't they both 4 bytes, and you get to skip one indirection by not using references? (The compiler probably optimizes that out, but then why the change?)

@gulafaran
Copy link
Contributor Author

@gulafaran, is it worthy to replace float with float const&? Aren't they both 4 bytes, and you get to skip one indirection by not using references? (The compiler probably optimizes that out, but then why the change?)

yeah thats true, it slinged out in mere force of habit. it probably is faster with just passing by value and not having a potential indirections, atleast when it comes to small types like this. float/int etc. now if it even makes an measurable difference i doubt it heh

@gulafaran
Copy link
Contributor Author

@gulafaran, is it worthy to replace float with float const&? Aren't they both 4 bytes, and you get to skip one indirection by not using references? (The compiler probably optimizes that out, but then why the change?)

yeah thats true, it slinged out in mere force of habit. it probably is faster with just passing by value and not having a potential indirections, atleast when it comes to small types like this. float/int etc. now if it even makes an measurable difference i doubt it heh

also from what i understand it also entirerly depends on your architecture, compiler, the phase shift of the moon and your bitbots aligning in your cache to tell what is faster and what is not when it comes to these smaller types :D so il leave the decision to vaxry how he wants it

@vaxerski vaxerski merged commit 943b3d4 into hyprwm:main Nov 22, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants