Skip to content

Commit 9b6d971

Browse files
authored
perf: improve ScriptContext performance (#1264)
1 parent 1dbed74 commit 9b6d971

13 files changed

Lines changed: 1134 additions & 1024 deletions

File tree

eng/run-benchmarks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ await poll(restartTimeout, 5_000, "Server not ready yet", async () => {
102102
});
103103

104104
$.logStep("Server is back online.");
105-
await $.sleep(5_000);
105+
await $.sleep("10s");
106106

107107
// ── Run benchmarks ──────────────────────────────────────────────────────
108108

managed/CounterStrikeSharp.API/BaseNative.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using FastGenericNew;
12
/*
23
* This file is part of CounterStrikeSharp.
34
* CounterStrikeSharp is free software: you can redistribute it and/or modify
@@ -67,7 +68,7 @@ protected virtual void EnsureNativeHandle()
6768
/// <returns></returns>
6869
public T As<T>() where T : NativeObject
6970
{
70-
return (T)Activator.CreateInstance(typeof(T), this.Handle);
71+
return FastNew.CreateInstance<T, IntPtr>(this.Handle);
7172
}
7273
}
7374
}

managed/CounterStrikeSharp.API/Core/Model/CBaseEntity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using FastGenericNew;
12
using System;
23
using System.Numerics;
34
using System.Runtime.InteropServices;
@@ -87,7 +88,7 @@ public void DispatchSpawn()
8788
{
8889
Guard.IsValidEntity(this);
8990

90-
return (T)Activator.CreateInstance(typeof(T), Marshal.ReadIntPtr(SubclassID.Handle + 4));
91+
return FastNew.CreateInstance<T, IntPtr>(Marshal.ReadIntPtr(SubclassID.Handle + 4));
9192
}
9293

9394
/// <summary>

managed/CounterStrikeSharp.API/Core/Model/CCSPlayer_ItemServices.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using FastGenericNew;
12
/*
23
* This file is part of CounterStrikeSharp.
34
* CounterStrikeSharp is free software: you can redistribute it and/or modify
@@ -54,7 +55,7 @@ public void RemoveWeapons()
5455
if (pointer == IntPtr.Zero)
5556
return null;
5657

57-
return (T)Activator.CreateInstance(typeof(T), pointer)!;
58+
return FastNew.CreateInstance<T, IntPtr>(pointer);
5859
}
5960

6061
public AcquireResult CanAcquire(CEconItemView itemView, AcquireMethod method, IntPtr unknown = 0)

managed/CounterStrikeSharp.API/Core/Model/NetworkedVector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using FastGenericNew;
12
using System;
23
using System.Collections;
34
using System.Collections.Generic;
@@ -29,7 +30,7 @@ public T this[int index]
2930
throw new NotSupportedException("Networked vectors currently only support CHandle<T>");
3031
}
3132

32-
return (T)Activator.CreateInstance(typeof(T), NativeAPI.GetNetworkVectorElementAt(Handle, index));
33+
return FastNew.CreateInstance<T, IntPtr>(NativeAPI.GetNetworkVectorElementAt(Handle, index));
3334
}
3435
}
3536

0 commit comments

Comments
 (0)