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

Use in keyword wherever possible #194

Open
HellGate94 opened this issue Aug 11, 2021 · 2 comments
Open

Use in keyword wherever possible #194

HellGate94 opened this issue Aug 11, 2021 · 2 comments

Comments

@HellGate94
Copy link

HellGate94 commented Aug 11, 2021

there is no need to indirectly create a copy of parameters in most cases. using in can drastically improve performance for several methods and operators.

for example changing float4 multiply to

    public static float4 operator * (in float4 lhs, in float4 rhs) { return new float4 (lhs.x * rhs.x, lhs.y * rhs.y, lhs.z * rhs.z, lhs.w * rhs.w); }

results in a massive performance improvement in .Net 5 (hopefully similar in Mono) ~3.1 ns vs ~0.1 ns (intel 7th gen)

burst might do that already internally but it could finally make this library faster than the built in Vector3/4/... outside of Burst

PS: soon™ https://docs.microsoft.com/en-us/dotnet/api/system.math.sincos?view=net-6.0

@unpacklo
Copy link
Collaborator

Thanks for the report. This is something I'd like to do in a future version of Mathematics because without it, as you say, performance can be quite poor without Burst. The main hurdle right now is ensuring that any usages of in doesn't break Burst compilation.

@MrUnbelievable92
Copy link

I have only seen poor performance from in for simple methods in the current Mono runtime.

Burst does (luckily) not do that internally - it rather inlines the function itself. The in keyword converts the following parameter to a pointer to that type. Compilers get very suspicious when that is the case, especially when there are multiple pointers to the same type as function arguments. They usually don't inline these functions to be conservative, which is definitely the case with the current runtime.

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

No branches or pull requests

3 participants