Update to Faster math conversions #8392
Open
+52
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was looking through Mono to see if you all were having the same problems of the existing System.Numerics library built into .NET or if you were still using your own math classes.
I noticed the conversion methods were creating new values instead of using the Unsafe class which has been very helpful for our Bepu to Stride conversions that were a bottleneck before finding this option.
This PR changes the built in conversions to use
Unsafe.As
to convert instead of creating a new value.The one thing I dont understand is why the implicit conversions for
Matrix
are as fast as theUnsafe.As
but the implicit forVector3
andQuaternion
are what I would expect from using the new keyword.This is the example where I forced
![image](https://private-user-images.githubusercontent.com/73259914/340744722-e0485b27-cfb4-4f43-87f5-0203fdc20e3f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2MzA5NzUsIm5iZiI6MTcxOTYzMDY3NSwicGF0aCI6Ii83MzI1OTkxNC8zNDA3NDQ3MjItZTA0ODViMjctY2ZiNC00ZjQzLTg3ZjUtMDIwM2ZkYzIwZTNmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDAzMTExNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA2NzhjODY1ZDY4NmUwZjUxY2U2YjAxY2ZhMWVmYmE3NTNmODZmOTk1MzU5Y2U4MmUzYTNlZGM2Y2Y3YzRlMDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.3AvbXT2kBxiW80HoTmafF5TGNtsMt7ZWUtZja0CpIIw)
Matrix
to use the new keyword the rest are using the existing implicit conversion:And this is the example of using the
![image](https://private-user-images.githubusercontent.com/73259914/340746972-a9ce95cf-53cc-4e0b-a590-0e9859ba3967.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2MzA5NzUsIm5iZiI6MTcxOTYzMDY3NSwicGF0aCI6Ii83MzI1OTkxNC8zNDA3NDY5NzItYTljZTk1Y2YtNTNjYy00ZTBiLWE1OTAtMGU5ODU5YmEzOTY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDAzMTExNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzOGIwMWRkYmFjMTM2ZTgzMmIyNzQ0OTA3MWEwNmJiNjljODI4N2I1OTg5MDIzN2ViZjY5OWU5ZDY1MzkyODMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.ft_r32L4S69xUPe0XVZqckAFhocckatXzvKKVm-G8Uo)
Matrix
implcit conversion:here is the gist files of the benchmarks I ran https://gist.github.com/Doprez/04d61e03915a9527a482cddbaa826544