-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
Add new cache for UIComponents
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Benchmarks | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
benchmark: | ||
name: Run benchmarks on Linux in ${{ matrix.unityVersion }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
unityVersion: | ||
- 2020.3.33f1 | ||
- 2021.3.1f1 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: Library | ||
key: Library-StandaloneLinux64-${{ matrix.unityVersion }}-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} | ||
restore-keys: | | ||
Library-StandaloneLinux64-${{ matrix.unityVersion }}- | ||
Library-StandaloneLinux64- | ||
Library- | ||
- uses: game-ci/unity-test-runner@v2 | ||
id: benchmarkRunner | ||
env: | ||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | ||
with: | ||
unityVersion: ${{ matrix.unityVersion }} | ||
githubToken: ${{ secrets.GITHUB_TOKEN }} | ||
testMode: EditMode | ||
customParameters: -releaseCodeOptimization -assemblyNames "UIComponents.Benchmarks" | ||
coverageOptions: "" | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: Benchmark results | ||
path: ${{ steps.benchmarkRunner.outputs.artifactsPath }}/editmode-results.xml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<UXML xmlns:ui="UnityEngine.UIElements"> | ||
<ui:Label name="addressables-example-header" text="AddressablesExampleComponent" /> | ||
<ui:Label text="This is an example of a component loaded with Addressables." /> | ||
<ui:VisualElement class="white-box"> | ||
<ui:Label name="addressables-example-header" text="AddressablesExampleComponent" /> | ||
<ui:Label text="This is an example of a component loaded with Addressables." /> | ||
</ui:VisualElement> | ||
</UXML> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.white-box { | ||
border-radius: 6px; | ||
border-width: 2px; | ||
border-color: white; | ||
padding: 8px; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using NUnit.Framework; | ||
using UIComponents.Addressables; | ||
using Unity.PerformanceTesting; | ||
|
||
namespace UIComponents.Benchmarks.AssetLoading | ||
{ | ||
[TestFixture] | ||
public class AddressablesAssetLoadBenchmarks | ||
{ | ||
[AssetPath("Assets/Samples/Addressables/Data")] | ||
[Layout("AddressablesExampleComponent.uxml")] | ||
[Stylesheet("AddressablesExampleComponent.uss")] | ||
[Stylesheet("Box.uss")] | ||
[Dependency(typeof(IAssetResolver), provide: typeof(AddressableAssetResolver))] | ||
private class ComponentWithAssets : UIComponent {} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithWarmCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithWarmCache<ComponentWithAssets>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithColdCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithColdCache<ComponentWithAssets>(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NUnit.Framework; | ||
using UIComponents.Editor; | ||
using Unity.PerformanceTesting; | ||
|
||
namespace UIComponents.Benchmarks.AssetLoading | ||
{ | ||
public class AssetDatabaseAssetLoadBenchmarks | ||
{ | ||
[Layout("AssetDatabaseLayoutFile.uxml")] | ||
[Stylesheet("AssetDatabaseStylesFile.uss")] | ||
[Stylesheet("CommonMargins.uss")] | ||
[AssetPath("Assets/UIComponents.Benchmarks/AssetLoading")] | ||
[Dependency(typeof(IAssetResolver), provide: typeof(AssetDatabaseAssetResolver))] | ||
private class ComponentWithAssets : UIComponent {} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithWarmCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithWarmCache<ComponentWithAssets>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithColdCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithColdCache<ComponentWithAssets>(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<UXML xmlns:ui="UnityEngine.UIElements"> | ||
<ui:Label name="assetdatabase-example-header" text="AssetDatabaseExampleComponent" /> | ||
<ui:VisualElement class="italic-label-container"> | ||
<ui:Label text="This is an example of a component loaded from AssetDatabase." /> | ||
<ui:Label text="AssetDatabase is used in the editor." /> | ||
</ui:VisualElement> | ||
</UXML> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#assetdatabase-example-header { | ||
font-size: 20px; | ||
-unity-font-style: bold; | ||
white-space: normal; | ||
} | ||
|
||
.italic-label-container { | ||
width: 100%; | ||
} | ||
|
||
.italic-label-container Label { | ||
white-space: normal; | ||
-unity-font-style: italic; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.top-margin { | ||
margin-top: 10px; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using NUnit.Framework; | ||
using Unity.PerformanceTesting; | ||
|
||
namespace UIComponents.Benchmarks.AssetLoading | ||
{ | ||
public class ResourcesAssetLoadBenchmarks | ||
{ | ||
[Layout("Components/ResourcesExampleComponent")] | ||
[Stylesheet("Components/ResourcesExampleComponent.style")] | ||
[Stylesheet("Margins")] | ||
private class ComponentWithAssets : UIComponent {} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithWarmCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithWarmCache<ComponentWithAssets>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithColdCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithColdCache<ComponentWithAssets>(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Unity.PerformanceTesting; | ||
|
||
namespace UIComponents.Benchmarks | ||
{ | ||
public static class BenchmarkUtils | ||
{ | ||
public const string Version = "0.9.0.0"; | ||
|
||
private static SampleGroup[] GetProfilerMarkers() | ||
{ | ||
return new[] | ||
{ | ||
new SampleGroup("UIComponent.DependencySetup", SampleUnit.Microsecond), | ||
new SampleGroup("UIComponent.CacheSetup", SampleUnit.Microsecond), | ||
new SampleGroup("UIComponent.LayoutAndStylesSetup", SampleUnit.Microsecond) | ||
}; | ||
} | ||
|
||
public static void MeasureComponentInitWithColdCache<TComponent>() where TComponent : UIComponent, new() | ||
{ | ||
Measure.Method(() => { new TComponent(); }) | ||
.SetUp(() => | ||
{ | ||
UIComponent.ClearCache<TComponent>(); | ||
DependencyInjector.RemoveInjector(typeof(TComponent)); | ||
}) | ||
.SampleGroup(new SampleGroup("Cold Cache Time", SampleUnit.Microsecond)) | ||
.ProfilerMarkers(GetProfilerMarkers()) | ||
.MeasurementCount(50) | ||
.IterationsPerMeasurement(100) | ||
.GC() | ||
.Run(); | ||
} | ||
|
||
public static void MeasureComponentInitWithWarmCache<TComponent>() where TComponent : UIComponent, new() | ||
{ | ||
Measure.Method(() => { new TComponent(); }) | ||
.SampleGroup(new SampleGroup("Warm Cache Time", SampleUnit.Microsecond)) | ||
.MeasurementCount(50) | ||
.IterationsPerMeasurement(100) | ||
.ProfilerMarkers(GetProfilerMarkers()) | ||
.GC() | ||
.Run(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using NUnit.Framework; | ||
using Unity.PerformanceTesting; | ||
|
||
namespace UIComponents.Benchmarks | ||
{ | ||
public class UIComponentInitBenchmarks | ||
{ | ||
private class EmptyComponent : UIComponent {} | ||
|
||
private interface IDependency {} | ||
|
||
private class DependencyProvider : IDependency {} | ||
|
||
[Dependency(typeof(IDependency), provide: typeof(DependencyProvider))] | ||
private class ComponentWithDependency : UIComponent {} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeEmptyComponentWithWarmCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithWarmCache<EmptyComponent>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeEmptyComponentWithColdCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithColdCache<EmptyComponent>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithDependencyWithWarmCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithWarmCache<ComponentWithDependency>(); | ||
} | ||
|
||
[Test, Performance, Version(BenchmarkUtils.Version)] | ||
public void InitializeComponentWithDependencyWithColdCache() | ||
{ | ||
BenchmarkUtils.MeasureComponentInitWithColdCache<ComponentWithDependency>(); | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "UIComponents.Benchmarks", | ||
"rootNamespace": "UIComponents", | ||
"references": [ | ||
"Unity.PerformanceTesting", | ||
"UnityEngine.TestRunner", | ||
"UnityEditor.TestRunner", | ||
"UIComponents", | ||
"UIComponents.Addressables", | ||
"UIComponents.Editor" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.