Skip to content

Perf: Potential performance issue in MappedClassField #5

Description

@EggAllocationService

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ExplorationThings that should be looked at in the future

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions