Unity-Technologies / Unity-Technologies/Unity.Mathematics

Use in keyword wherever possible

Open
#194 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.4k
Forks
159
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the float4 multiplication operator shown in the issue, then inspect other methods and operators that copy parameters. Determine which cases can use the in keyword without changing behavior, and verify that the affected operations retain their behavior while improving performance outside Burst.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.