Skip to content

perf: improve ScriptContext performance#1264

Merged
roflmuffin merged 8 commits intomainfrom
perf/improvements
Apr 10, 2026
Merged

perf: improve ScriptContext performance#1264
roflmuffin merged 8 commits intomainfrom
perf/improvements

Conversation

@roflmuffin
Copy link
Copy Markdown
Owner

@roflmuffin roflmuffin commented Apr 6, 2026

Benchmark Diff: perf/improvements vs benchmarking baseline

New: 72b5491c (2026-04-10) | Baseline: ae604f16 (2026-03-23)

Entity Lifecycle

Benchmark Baseline (ns) New (ns) Delta (ns) Change
Entity create+spawn info_target 11,029 8,178 -2,851 -25.9%
GetPlayerFromSlot 580 140 -440 -75.9%

GameEvent

Benchmark Baseline (ns) New (ns) Delta (ns) Change
GameEvent Fire 4,211 2,683 -1,528 -36.3%

Mixed

Benchmark Baseline (ns) New (ns) Delta (ns) Change
Mixed (4 natives/iter) 338 156 -182 -53.8%

NetMessage

Benchmark Baseline (ns) New (ns) Delta (ns) Change
NetMessage Send 18,733 11,883 -6,850 -36.6%

Primitive Args

Benchmark Baseline (ns) New (ns) Delta (ns) Change
GetConvarFlags (ushort → ulong) 415 185 -230 -55.4%
GetConvarType (ushort → short) 422 165 -257 -60.9%

Primitive Return

Benchmark Baseline (ns) New (ns) Delta (ns) Change
GetEngineTime (double, no args) 251 145 -106 -42.2%
GetMaxClients (int, no args) 234 115 -119 -50.9%
GetServerCurrentTime (float, no args) 257 141 -116 -45.1%
GetTickCount (int, no args) 220 76 -144 -65.5%
GetTickInterval (float, no args) 230 139 -91 -39.6%
IsServerPaused (bool, no args) 301 121 -180 -59.8%

Schema

Benchmark Baseline (ns) New (ns) Delta (ns) Change
GetDeclaredClass (CBodyComponent) 475 115 -360 -75.8%
GetSchemaValue<int> (Health) 124 88 -36 -29.0%
SchemaOffset 4 keys 103 63 -40 -38.8%
SchemaOffset cached 99 61 -38 -38.4%

String Push

Benchmark Baseline (ns) New (ns) Delta (ns) Change
FindConvar (string → pointer) 475 237 -238 -50.1%
PushString 9 bytes 432 248 -184 -42.6%
PushString 200 bytes 766 524 -242 -31.6%
PushString 2000 bytes 2,601 2,090 -511 -19.6%
PushString 9000 bytes (overflow) 9,880 8,347 -1,533 -15.5%

String Return

Benchmark Baseline (ns) New (ns) Delta (ns) Change
GetConvarName (ushort → string) 409 208 -201 -49.1%
GetMapName (string, no args) 368 435 +67 +18.2%

Virtual Function

Benchmark Baseline (ns) New (ns) Delta (ns) Change
VFunc IsPlayerPawn (high-level API) 2,903 1,781 -1,122 -38.7%
VFunc IsPlayerPawn (pre-created delegate) 758 403 -355 -46.8%

…hal.StructureToPtr. Primitive args 28-30% faster, VFunc 35-40% faster, mixed 13% faster.

Result: {"status":"keep","primitive_args_ns":296,"GetConvarFlags_ns":296,"GetConvarType_ns":296,"Mixed_ns":301,"VFunc_preCreated_ns":480,"VFunc_highLevel_ns":1942,"GetConvarName_ns":282}
…rToStructure boxing on return path. Primitive returns 28-48% faster, primitive args 31-39% faster, mixed 33% faster.

Result: {"status":"keep","primitive_args_ns":193,"GetConvarFlags_ns":205,"GetConvarType_ns":181,"Mixed_ns":203,"VFunc_preCreated_ns":502,"VFunc_highLevel_ns":1926,"GetConvarName_ns":272}

# Conflicts:
#	autoresearch.jsonl
…it CheckErrors into fast path (no error) + NoInlining slow path. Skip GlobalCleanUp lock when no finalizers queued. GetTickCount 81ns (was 116), mixed 183ns (was 203).

Result: {"status":"keep","primitive_args_ns":172,"GetConvarFlags_ns":184,"GetConvarType_ns":160,"Mixed_ns":183,"VFunc_preCreated_ns":424,"VFunc_highLevel_ns":1805,"GetConvarName_ns":253}

# Conflicts:
#	autoresearch.jsonl
…keNativeInternal. Small but consistent improvement across most benchmarks. Primitive args 172→170ns, GetConvarName 253→241ns.

Result: {"status":"keep","primitive_args_ns":170,"GetConvarFlags_ns":175,"GetConvarType_ns":165,"Mixed_ns":182,"VFunc_preCreated_ns":441,"VFunc_highLevel_ns":1751,"GetConvarName_ns":241}

# Conflicts:
#	autoresearch.jsonl
…izer + lambda per string. String push 20-39% faster, mixed 17% faster, GameEvent 19% faster. 9KB overflow path unchanged.

Result: {"status":"keep","primitive_args_ns":169,"GetConvarFlags_ns":173,"GetConvarType_ns":164,"Mixed_ns":151,"VFunc_preCreated_ns":414,"VFunc_highLevel_ns":1784,"GetConvarName_ns":240}
…tilities, CHandle, BaseNative, ScriptContext. GetDeclaredClass 508→115ns (77% faster), GetPlayerFromSlot 478→139ns (71% faster), NetMessage 26% faster.

Result: {"status":"keep","primitive_args_ns":164,"GetConvarFlags_ns":171,"GetConvarType_ns":157,"Mixed_ns":149,"VFunc_preCreated_ns":431,"VFunc_highLevel_ns":1956,"GetConvarName_ns":242}

# Conflicts:
#	autoresearch.jsonl
@roflmuffin roflmuffin marked this pull request as ready for review April 10, 2026 09:29
@roflmuffin roflmuffin changed the title perf: improvements perf: improve ScriptContext performance Apr 10, 2026
@roflmuffin roflmuffin merged commit 9b6d971 into main Apr 10, 2026
6 checks passed
@roflmuffin roflmuffin deleted the perf/improvements branch April 10, 2026 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant