Skip to content

Commit

Permalink
updates submodule & fixes content benchmarks & sets up ci (#11851)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRitter authored Oct 11, 2022
1 parent 576443f commit 4ef3891
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 12 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Benchmarks
on:
workflow_dispatch:
schedule:
- cron: '0 8 * * *'
push:
tags:
- 'v*'

concurrency: benchmarks

env:
ROBUST_BENCHMARKS_ENABLE_SQL: 1
ROBUST_BENCHMARKS_SQL_ADDRESS: ${{ secrets.BENCHMARKS_WRITE_ADDRESS }}
ROBUST_BENCHMARKS_SQL_PORT: ${{ secrets.BENCHMARKS_WRITE_PORT }}
ROBUST_BENCHMARKS_SQL_USER: ${{ secrets.BENCHMARKS_WRITE_USER }}
ROBUST_BENCHMARKS_SQL_PASSWORD: ${{ secrets.BENCHMARKS_WRITE_PASSWORD }}
ROBUST_BENCHMARKS_SQL_DATABASE: content_benchmarks

jobs:
benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
- name: Get Engine version
run: |
cd RobustToolbox
git fetch --depth=1
echo "::set-output name=out::$(git rev-parse HEAD)"
id: engine_version
- name: Run script on centcomm
uses: appleboy/ssh-action@master
with:
host: centcomm.spacestation14.io
username: robust-benchmark-runner
key: ${{ secrets.CENTCOMM_ROBUST_BENCHMARK_RUNNER_KEY }}
command_timeout: 100000m
script: |
mkdir benchmark_run_${{ github.sha }}
cd benchmark_run_${{ github.sha }}
wget https://raw.githubusercontent.com/space-wizards/RobustToolbox/${{ steps.engine_version.outputs.out }}/Tools/run_benchmarks.py
python3 run_benchmarks.py "${{ secrets.BENCHMARKS_WRITE_ADDRESS }}" "${{ secrets.BENCHMARKS_WRITE_PORT }}" "${{ secrets.BENCHMARKS_WRITE_USER }}" "${{ secrets.BENCHMARKS_WRITE_PASSWORD }}" "${{ github.sha }}"
rm run_benchmarks.py
cd ..
rmdir benchmark_run_${{ github.sha }}
4 changes: 3 additions & 1 deletion Content.Benchmarks/ColorInterpolateBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
using System;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using SysVector4 = System.Numerics.Vector4;

namespace Content.Benchmarks
{
[DisassemblyDiagnoser]
public sealed class ColorInterpolateBenchmark
[Virtual]
public class ColorInterpolateBenchmark
{
#if NETCOREAPP
private const MethodImplOptions AggressiveOpt = MethodImplOptions.AggressiveOptimization;
Expand Down
4 changes: 3 additions & 1 deletion Content.Benchmarks/ComponentFetchBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;
using Robust.Shared.Utility;

namespace Content.Benchmarks
{
[SimpleJob]
public sealed class ComponentFetchBenchmark
[Virtual]
public class ComponentFetchBenchmark
{
[Params(5000)] public int NEnt { get; set; }

Expand Down
1 change: 1 addition & 0 deletions Content.Benchmarks/Content.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
<ProjectReference Include="..\Content.Tests\Content.Tests.csproj" />
<ProjectReference Include="..\Content.IntegrationTests\Content.IntegrationTests.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Benchmarks\Robust.Benchmarks.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion Content.Benchmarks/DependencyInjectBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Content.Benchmarks
{
// To actually run this benchmark you'll have to make DependencyCollection public so it's accessible.
public sealed class DependencyInjectBenchmark
[Virtual]
public class DependencyInjectBenchmark
{
[Params(InjectMode.Reflection, InjectMode.DynamicMethod)]
public InjectMode Mode { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion Content.Benchmarks/DynamicTreeBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;
using Robust.Shared.Maths;
using Robust.Shared.Physics;

namespace Content.Benchmarks
{
[SimpleJob, MemoryDiagnoser]
public sealed class DynamicTreeBenchmark
[Virtual]
public class DynamicTreeBenchmark
{
private static readonly Box2[] _aabbs1 =
{
Expand Down
4 changes: 3 additions & 1 deletion Content.Benchmarks/EntityFetchBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;
using Robust.Shared.Utility;

namespace Content.Benchmarks
{
[SimpleJob]
public sealed class EntityFetchBenchmark
[Virtual]
public class EntityFetchBenchmark
{
[Params(1000)] public int N { get; set; }

Expand Down
4 changes: 3 additions & 1 deletion Content.Benchmarks/EntityManagerGetAllComponents.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BenchmarkDotNet.Attributes;
using Moq;
using Robust.Shared.Analyzers;
using Robust.Shared.Exceptions;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
Expand All @@ -9,7 +10,8 @@

namespace Content.Benchmarks
{
public sealed class EntityManagerGetAllComponents
[Virtual]
public class EntityManagerGetAllComponents
{
private IEntityManager _entityManager;

Expand Down
42 changes: 42 additions & 0 deletions Content.Benchmarks/MapLoadBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using Content.IntegrationTests;
using Content.Server.Maps;
using Robust.Server.Maps;
using Robust.Shared;
using Robust.Shared.Analyzers;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;

namespace Content.Benchmarks;

[Virtual]
public class MapLoadBenchmark
{
private PairTracker _pair = default!;

[GlobalSetup]
public void Setup()
{
ProgramShared.PathOffset = "../../../../";
_pair = PoolManager.GetServerClient().GetAwaiter().GetResult();
Paths = _pair.Pair.Server.ResolveDependency<IPrototypeManager>()
.EnumeratePrototypes<GameMapPrototype>().ToDictionary(x => x.ID, x => x.MapPath.ToString());
IoCManager.InitThread(_pair.Pair.Server.InstanceDependencyCollection);
}

public static IEnumerable<string> MapsSource { get; set; }

[ParamsSource(nameof(MapsSource))] public string Map;

public static Dictionary<string, string> Paths;

[Benchmark]
public void LoadMap()
{
_pair.Pair.Server.ResolveDependency<IMapLoader>().LoadMap(new MapId(10), Paths[Map]);
}
}
4 changes: 3 additions & 1 deletion Content.Benchmarks/NetSerializerIntBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using System.Buffers.Binary;
using System.IO;
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;

namespace Content.Benchmarks
{
[SimpleJob]
public sealed class NetSerializerIntBenchmark
[Virtual]
public class NetSerializerIntBenchmark
{
private MemoryStream _writeStream;
private MemoryStream _readStream;
Expand Down
4 changes: 3 additions & 1 deletion Content.Benchmarks/NetSerializerStringBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using BenchmarkDotNet.Attributes;
using Lidgren.Network;
using NetSerializer;
using Robust.Shared.Analyzers;

namespace Content.Benchmarks
{
// Code for the *Slow and *Unsafe implementations taken from NetSerializer, licensed under the MIT license.

[MemoryDiagnoser]
public sealed class NetSerializerStringBenchmark
[Virtual]
public class NetSerializerStringBenchmark
{
private const int StringByteBufferLength = 256;
private const int StringCharBufferLength = 128;
Expand Down
30 changes: 28 additions & 2 deletions Content.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
using BenchmarkDotNet.Running;
using System;
using System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using Content.IntegrationTests;
using Content.Server.Maps;
using Robust.Benchmarks.Configs;
using Robust.Shared.Prototypes;

namespace Content.Benchmarks
{
internal static class Program
{

public static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
MainAsync(args).GetAwaiter().GetResult();
}

public static async Task MainAsync(string[] args)
{
var pair = await PoolManager.GetServerClient();
var gameMaps = pair.Pair.Server.ResolveDependency<IPrototypeManager>().EnumeratePrototypes<GameMapPrototype>().ToList();
MapLoadBenchmark.MapsSource = gameMaps.Select(x => x.ID);

#if DEBUG
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\nWARNING: YOU ARE RUNNING A DEBUG BUILD, USE A RELEASE BUILD FOR AN ACCURATE BENCHMARK");
Console.WriteLine("THE DEBUG BUILD IS ONLY GOOD FOR FIXING A CRASHING BENCHMARK\n");
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
#else
var config = Environment.GetEnvironmentVariable("ROBUST_BENCHMARKS_ENABLE_SQL") != null ? DefaultSQLConfig.Instance : null;
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config);
#endif
}
}
}
4 changes: 3 additions & 1 deletion Content.Benchmarks/StereoToMonoBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Runtime.Intrinsics.X86;
using BenchmarkDotNet.Attributes;
using Robust.Shared.Analyzers;

namespace Content.Benchmarks
{
public sealed class StereoToMonoBenchmark
[Virtual]
public class StereoToMonoBenchmark
{
[Params(128, 256, 512)]
public int N { get; set; }
Expand Down

0 comments on commit 4ef3891

Please sign in to comment.