Skip to content

Provide a way to run benchmarks under Unity Mono and IL2CPP #1860

Open
@MichalPetryka

Description

@MichalPetryka

Currently, there is no official (but there have been attempts it seems, looking at #1838 and #759) way to use BenchmarkDotNet under Unity nor to benchmark code running under Unity. This has resulted in many improper benchmarks with incorrect results being shared around the internet. Providing an option to use Unity Mono and IL2CPP as runtimes would be highly beneficial for game development, since that is an usecase where perfomance often matters.

I thought about how the support should look like and I've came up with a few things:

  • BenchmarkDotNet would contain a project template that would contain the code required to run the benchmarks, where the benchmark code would be copied on build.
  • Since Unity allows only a single instance of a project to be open at once, BenchmarkDotNet would need to create a separate copy of the project generated from the template or to compile them sequentially.
  • The app would be a full Unity app for the Mono runtime, instead of just running the code with their fork of Mono to also measure the engines real impact on performance and also since that would not be possible with IL2CPP.
  • The app would use Unitys headless mode to reduce the performance overhead and to allow issue-less measurement under headless server environments.
  • Nuget support would have to be realized by downloading the dependencies and copying them into the created project.
  • Native libraries referenced in the project would need to be similarly copied.
  • Unlike the Mono runtime target, Unity runtimes would be versioned like .Net.
  • The engine would need to be installed manually by the user.
  • In order to allow benchmarking of the Unity API, BenchmarkDotNet would need to provide reference assemblies allowing access to them. This could be realised by providing a separate BenchmarkDotNet.Unity Nuget package. This would need to be versioned accordingly to Unity
  • The IL2CPP target, being a Full AOT runtime like NativeAOT (formerly CoreRT), would face the same restrictions.

Open questions:

  • Should BenchmarkDotNet build a code binary with dotnet and then include that in the project or copy the code directly?
  • Unlike dotnet, Unity doesn't add itself to PATH nor provide an easy way to access its install location. This could make specifing the Engine path by the user required.
  • Should the template project provide optional Unity features like DOTS in order to make it possible to benchmark them?
  • I'm not sure if all diagnosers like MemoryDiagnoser or DisassemblyDiagnoser (this project could provide some insight with this one for Mono) would be possible to implement.
  • AFAIK Unitys Terms of Service wouldn't allow the redistribution of referenece assemblies generated against their code, so this would require some cooperation from Unity and their legal team.

There has been recent talk about this on Unitys forum, which tells us that Unity staff would be interested in this too, at least according to @joshpeterson.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions