One performance issue on the horizon is the use of reflection in the default property extractor. Reflection in C# is pretty slow. In our case there's evidence that using FieldInfo as is currently done in the MappedClassField implementation is around sixty times slower than direct assignment [1].
Some steps should be taken to make sure that this is actually a problem:
- Performance testing with lots of mapped properties exposed in libmapper
- Running some flamegraphs to see where any problems actually lie
Potential performance improvement paths
Runtime Code Generation
Use DynamicMethod to generate getters/setters at runtime.
Pros:
- Works for any Component type thrown at us, and is definitely faster than just reflection.
Potential issues are platforms where runtime code generation isn't possible or is very slow, such as iOS
Compile-time Code Generators
Use the Roslyn generators system to automatically create concrete classes implementing IMappedProperty. This is probably the fastest implementation possible
References
[1]: https://medium.com/@veyseler.cs.ist/performance-test-for-setting-a-field-in-c-with-reflection-3e2e41d8a2ab
One performance issue on the horizon is the use of reflection in the default property extractor. Reflection in C# is pretty slow. In our case there's evidence that using
FieldInfoas is currently done in theMappedClassFieldimplementation is around sixty times slower than direct assignment [1].Some steps should be taken to make sure that this is actually a problem:
Potential performance improvement paths
Runtime Code Generation
Use DynamicMethod to generate getters/setters at runtime.
Pros:
Potential issues are platforms where runtime code generation isn't possible or is very slow, such as iOS
Compile-time Code Generators
Use the Roslyn generators system to automatically create concrete classes implementing IMappedProperty. This is probably the fastest implementation possible
References
[1]: https://medium.com/@veyseler.cs.ist/performance-test-for-setting-a-field-in-c-with-reflection-3e2e41d8a2ab