question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Investigate By-Ref Vector and Matrix Operators in C# 8.0

See original GitHub issue

Summary

As mentioned in issue #598, the new in parameter keyword is allowed on operators and using literal values, so operator implementations can supersede the previous static by-ref operator alternatives.

Analysis

  • Wait until the core has adopted C# 7.2.
  • Make sure using the in keyword implicitly with non-referencable values (like literals or property return values) has no negative impact on performance. Read the docs, and if that’s not 100% clear, check out generated IL and x86 code in a sample project.
  • Remove all static by-ref methods from Vector2/3/4, Quaternion and Matrix3/4 if they have an operator equivalent.
  • Use the in keyword on parameters provided to the operators in question.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
Barsonaxcommented, Jun 26, 2019

As a further enhancement one can add readonly to properties and methods etc now in C#8.0 to denote they do not change state: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#readonly-members

(in C# 7.3 this was only possible on struct level)

This will enable the compiler to skip more defensive copies.

1reaction
Barsonaxcommented, Nov 8, 2018

There are cases where defensive copies might occur when using the in keyword. This can reduce the performance. Making the struct readonly will prevent this.

https://blogs.msdn.microsoft.com/seteplia/2018/03/07/the-in-modifier-and-the-readonly-structs-in-c/

However since the X, Y etc fields are part of the public API its basically a breaking change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Easy matrix - Page 2
(I use array of matrix 1 to whatever, but 0 to whatever would be OK) ... operator * ( byref a as Matrix...
Read more >
7.5 Matrices and Matrix Operations - College Algebra 2e
We will investigate this idea further in the next section, but first we will look at basic matrix operations. Matrices. A matrix is...
Read more >
Performance: Matlab vs C++ Matrix vector multiplication
I have a slightly larger code, from which I am investigating a segment of matrix-vector multiplication. The larger code performs such ...
Read more >
2.2: Matrix multiplication and linear combinations
This means that we may define scalar multiplication and matrix addition operations using the corresponding vector operations.
Read more >
Matrix Operations - Yung-Yu's Notes
Vector : 1D Array#. We may use a 1D array (a contiguous memory buffer of sequentially ordered elements) to store a vector. Small...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found