perf: harden runtime for weaker hardware

This commit is contained in:
Rijad Zuzo
2026-08-12 10:02:45 +02:00
parent cd29da95e0
commit 34428d836a
47 changed files with 2164 additions and 243 deletions
+87 -2
View File
@@ -3,6 +3,23 @@ extends SceneTree
const SimulationManagerScript := preload("res://simulation/SimulationManager.gd")
const BenchmarkScript := preload("res://simulation/benchmark/SimulationScalingBenchmark.gd")
class CoverageDroppingManager:
extends "res://simulation/SimulationManager.gd"
var drop_after_simulation_ticks := -1
var simulation_ticks_seen := 0
var removed_combatant_id: StringName = &""
func simulate_tick() -> void:
super()
simulation_ticks_seen += 1
if simulation_ticks_seen != drop_after_simulation_ticks or npcs.is_empty():
return
removed_combatant_id = SimulationIds.npc_combatant_id(npcs[-1].id)
conflict_system.combatants.erase(removed_combatant_id)
var failures: Array[String] = []
@@ -21,9 +38,22 @@ func _run() -> void:
_check(first["fixture_valid"], "The prepared benchmark state should pass schema validation")
_check(
(
int(first["schema_version"]) == SimulationScalingBenchmark.SCHEMA_VERSION
and StringName(first["workload_id"]) == SimulationScalingBenchmark.WORKLOAD_ID
int(first["schema_version"]) == 2
and SimulationScalingBenchmark.SCHEMA_VERSION == 2
and (
int(first["simulation_state_schema_version"])
== SimulationStateRecord.SCHEMA_VERSION
)
and StringName(first["workload_id"]) == &"full_fidelity_combatant_headless_arrival_v2"
and (
SimulationScalingBenchmark.WORKLOAD_ID
== &"full_fidelity_combatant_headless_arrival_v2"
)
and int(first["population"]) == 12
and int(first["npc_combatant_count"]) == 12
and bool(first["npc_combatant_coverage_valid"])
and int(first["fixture_npc_combatant_count"]) == 12
and bool(first["fixture_combatants_valid"])
and int(first["history_seed_events"]) == 24
and int(first["measured_ticks"]) == 8
and int(first["npc_updates"]) == 96
@@ -59,6 +89,8 @@ func _run() -> void:
"arrivals_processed",
"warmup_arrivals",
"tick_interval",
"npc_combatant_count",
"npc_combatant_coverage_valid",
]:
_check(
first[deterministic_key] == repeated[deterministic_key],
@@ -68,6 +100,14 @@ func _run() -> void:
first["final_checksum"] != different_seed["final_checksum"],
"A different fixture seed should produce a different deterministic checksum"
)
_check(
_coverage_loss_is_rejected(2, 3, 2),
"Coverage lost on the final warmup tick should reject the benchmark result"
)
_check(
_coverage_loss_is_rejected(2, 3, 5),
"Coverage lost on the final measured tick should reject the benchmark result"
)
_finish()
@@ -82,12 +122,57 @@ func _run_case(seed_value: int) -> Dictionary:
manager.free()
return {}
var fixture_valid := SimulationStateRecord.from_json(manager.serialize_state()) != null
var fixture_npc_combatant_count := 0
var fixture_combatants_valid := true
for npc in manager.npcs:
var combatant: CombatantStateRecord = manager.conflict_system.get_combatant(
SimulationIds.npc_combatant_id(npc.id)
)
if (
combatant == null
or combatant.get_npc_id() != npc.id
or combatant.get_display_name() != npc.npc_name
or not combatant.get_position().is_equal_approx(npc.position)
):
fixture_combatants_valid = false
else:
fixture_npc_combatant_count += 1
var result: Dictionary = benchmark.measure_manager(manager, 12, 24, 2, 8)
result["fixture_valid"] = fixture_valid
result["fixture_npc_combatant_count"] = fixture_npc_combatant_count
result["fixture_combatants_valid"] = fixture_combatants_valid
manager.free()
return result
func _coverage_loss_is_rejected(
warmup_ticks: int, measured_ticks: int, drop_after_simulation_ticks: int
) -> bool:
var manager := CoverageDroppingManager.new()
manager.simulation_seed = 9010
manager.debug_logs = false
manager.set_process(false)
root.add_child(manager)
var benchmark := BenchmarkScript.new()
var prepared := benchmark.prepare_manager(manager, 4, 0, manager.simulation_seed)
if not prepared:
manager.free()
return false
var target_id := SimulationIds.npc_combatant_id(manager.npcs[-1].id)
var target_existed := manager.conflict_system.get_combatant(target_id) != null
manager.drop_after_simulation_ticks = drop_after_simulation_ticks
var result: Dictionary = benchmark.measure_manager(manager, 4, 0, warmup_ticks, measured_ticks)
var rejected_after_exact_drop := (
target_existed
and manager.simulation_ticks_seen == drop_after_simulation_ticks
and manager.removed_combatant_id == target_id
and manager.conflict_system.get_combatant(target_id) == null
and result.is_empty()
)
manager.free()
return rejected_after_exact_drop
func _check(condition: bool, message: String) -> void:
if not condition:
failures.append(message)