Allocations in Unity
Posted: 02 Apr 2022, 00:33
Hello Noesis!
I've been looking at performance recently in our application and have been primarily focused on removing allocations. With regard to Noesis, a source of lots of allocations comes from the boxing/unboxing that happens when casting primitives like floats, ints, and enums to object.
Another source of allocations in Noesis is the marshalling of strings to/from the native Noesis dll.
I have modified the Noesis C# code quite a bit at this point to eliminate this garbage:
- I'm using a "variant" struct that wraps all the primitive types to avoid the major sources of boxing/unboxing allocations
- I've inserted a cache to re-use strings that were being marshalled from native code to avoid those allocations
- In a few cases, I'm recycling/reusing event arguments to avoid allocations.
So, I have a couple questions:
First, I would happily share this code back with y'all because I would prefer not to maintain it! :D. Would y'all be interested in seeing the changes I've made and considering integrating them?
Second, I'm still concerned about the overall performance in my Unity application. In theory, I can access your native APIs from native code using Unity's Burst compiler, but I end up extremely limited with some of the types I can use in that context (for example, there are no managed objects in burst, so I don't have simple things like string (there are alternatives)). The main part of my code that I would like to run "native" would be updating the data model.
Would appreciate thoughts/feedback!
thanks,
sam
I've been looking at performance recently in our application and have been primarily focused on removing allocations. With regard to Noesis, a source of lots of allocations comes from the boxing/unboxing that happens when casting primitives like floats, ints, and enums to object.
Another source of allocations in Noesis is the marshalling of strings to/from the native Noesis dll.
I have modified the Noesis C# code quite a bit at this point to eliminate this garbage:
- I'm using a "variant" struct that wraps all the primitive types to avoid the major sources of boxing/unboxing allocations
- I've inserted a cache to re-use strings that were being marshalled from native code to avoid those allocations
- In a few cases, I'm recycling/reusing event arguments to avoid allocations.
So, I have a couple questions:
First, I would happily share this code back with y'all because I would prefer not to maintain it! :D. Would y'all be interested in seeing the changes I've made and considering integrating them?
Second, I'm still concerned about the overall performance in my Unity application. In theory, I can access your native APIs from native code using Unity's Burst compiler, but I end up extremely limited with some of the types I can use in that context (for example, there are no managed objects in burst, so I don't have simple things like string (there are alternatives)). The main part of my code that I would like to run "native" would be updating the data model.
Would appreciate thoughts/feedback!
thanks,
sam