diff --git a/ReleaseConsumerProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs b/ReleaseConsumerProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs index 3bc6852..307e961 100644 --- a/ReleaseConsumerProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs +++ b/ReleaseConsumerProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs @@ -16,6 +16,7 @@ using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using UnityEngine.TestTools; using UnityEngine.UIElements; +using Stopwatch = System.Diagnostics.Stopwatch; namespace GameCult.EveUnity.GenericClient.PlayModeTests { @@ -912,6 +913,7 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests Assert.That(captureFieldVolume, Is.Not.Null, "The generic client did not install its Fields volume lowerer before temporal settling."); const int temporalSettlingFrames = 128; + var temporalSettlingElapsed = Stopwatch.StartNew(); var initialCompositeCount = captureFieldVolume.CompositeCount; var temporalSettlingDeadline = Time.realtimeSinceStartup + 20f; while (captureFieldVolume.CompositeCount - initialCompositeCount < temporalSettlingFrames && @@ -923,6 +925,8 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests Assert.That(captureFieldVolume.CompositeCount - initialCompositeCount, Is.GreaterThanOrEqualTo(temporalSettlingFrames), "The pilot capture ran before the advertised temporal reconstruction had settled."); + Debug.Log($"EveUnity witness phase temporal-settling-128-frames took {temporalSettlingElapsed.Elapsed.TotalMilliseconds:0.###}ms."); + var pilotCaptureElapsed = Stopwatch.StartNew(); yield return null; RenderTexture.active = target; pixels = new Texture2D(captureWidth, captureHeight, TextureFormat.RGB24, false); @@ -950,7 +954,9 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests "The provider-authored player prefab has no renderer on its advertised map channel."); Assert.That(playerMapRendererFacts.Sum(fact => fact.renderedPixelCount), Is.Zero, "A provider-prefab map-channel renderer leaked into the pilot camera."); + Debug.Log($"EveUnity witness phase pilot-capture-and-renderer-probes took {pilotCaptureElapsed.Elapsed.TotalMilliseconds:0.###}ms."); + var mapCaptureElapsed = Stopwatch.StartNew(); mapRenderers = mapRenderers.Where(renderer => renderer != null).ToList(); Assert.That(mapRenderers, Is.Not.Empty, "All advertised map-channel renderers were destroyed before map capture."); @@ -981,6 +987,7 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(mapCapturePath))); File.WriteAllBytes(mapCapturePath, pixels.EncodeToPNG()); Assert.That(new FileInfo(mapCapturePath).Length, Is.GreaterThan(1024)); + Debug.Log($"EveUnity witness phase map-capture took {mapCaptureElapsed.Elapsed.TotalMilliseconds:0.###}ms."); var tractorReleaseVersion = runtime.ActiveVersion; var tractorRelease = host.SubmitAdvertisedActionValueIntent( playerId, diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs index a33aa8c..28cb7a7 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshLiveProviderTransport.cs @@ -12,6 +12,7 @@ using GameCult.Eve.UnityScene.Fields; using GameCult.Mesh; using GameCult.Networking; using UnityEngine; +using Stopwatch = System.Diagnostics.Stopwatch; #nullable enable @@ -171,13 +172,25 @@ namespace GameCult.Eve.UnityScene if (_bootstrapped) return; + var elapsed = Stopwatch.StartNew(); ResolveAdvertisement(forceRefresh: true); + TraceStartup("advertisement", elapsed); RefreshSurface(); + TraceStartup("surface", elapsed); RefreshAssetCatalog(); + TraceStartup("asset-catalog-and-bundles", elapsed); EnsureLiveSubscriptions(); + TraceStartup("subscriptions", elapsed); _bootstrapped = true; } + private static void TraceStartup(string phase, Stopwatch elapsed) + { + if (string.Equals(Environment.GetEnvironmentVariable("EVEUNITY_TRACE_STARTUP_PHASES"), "1", StringComparison.Ordinal)) + Debug.Log($"EveUnity startup phase {phase} took {elapsed.Elapsed.TotalMilliseconds:0.###}ms."); + elapsed.Restart(); + } + private static string FindComponentProp(EveSurfaceComponent component, string key) { var value = component.GetProp(key); @@ -1040,6 +1053,7 @@ namespace GameCult.Eve.UnityScene ReadCameraPolicies(selected.Select(selection => selection.Variant!)); foreach (var group in selected.GroupBy(selection => selection.Variant!.Uri, StringComparer.Ordinal)) { + var groupElapsed = Stopwatch.StartNew(); var variant = group.First().Variant!; var manifest = _snapshot!.FetchDocumentsAsync( recordKeys: new[] { variant.Uri }, @@ -1049,7 +1063,9 @@ namespace GameCult.Eve.UnityScene var descriptor = manifest.FirstOrDefault(); if (descriptor == null) throw new InvalidOperationException($"Provider asset bundle manifest '{variant.Uri}' was not available."); + TraceStartup("asset-manifest", groupElapsed); var bundle = LoadVerifiedBundle(descriptor, variant); + TraceStartup("asset-transfer-and-bundle-load", groupElapsed); if (bundle == null) throw new InvalidOperationException($"Unity could not load provider asset bundle '{variant.Uri}'."); _assetBundles.Add(bundle); @@ -1078,6 +1094,7 @@ namespace GameCult.Eve.UnityScene if (!string.IsNullOrWhiteSpace(role)) _prefabs[role] = prefab; } } + TraceStartup("bundle-assets", groupElapsed); } CurrentAssetCatalogVersion = catalog.Version; @@ -1164,10 +1181,12 @@ namespace GameCult.Eve.UnityScene var now = DateTimeOffset.UtcNow; var network = NetworkArtifactDescriptor(manifest, now, TimeSpan.FromMinutes(5)); + var elapsed = Stopwatch.StartNew(); var mapped = ContentTransfer() .FetchMappedContentAsync(manifest, network, now, TimeSpan.FromMinutes(5)) .GetAwaiter() .GetResult(); + TraceStartup("content-materialization", elapsed); var request = new CultMeshBodyValidationRequest { BodyId = network.BodyId, @@ -1191,13 +1210,19 @@ namespace GameCult.Eve.UnityScene CurrentAssetBodyTransportKind = negotiated.SelectedTransport; _assetBodyLeases.Add(negotiated.Lease); if (negotiated.SelectedTransport == CultMeshBodyTransportKind.SharedFileMapping) - return AssetBundle.LoadFromFile(mapped.VerifiedPath); + { + var bundle = AssetBundle.LoadFromFile(mapped.VerifiedPath); + TraceStartup("asset-bundle-load-from-file", elapsed); + return bundle; + } if (negotiated.Lease.Descriptor.ByteSize > int.MaxValue) throw new InvalidOperationException("Unity cannot lower a network asset body larger than one managed byte array."); var bytes = new byte[checked((int)negotiated.Lease.Descriptor.ByteSize)]; negotiated.Lease.CopyTo(0, bytes, 0, bytes.Length); - return AssetBundle.LoadFromMemory(bytes); + var loaded = AssetBundle.LoadFromMemory(bytes); + TraceStartup("asset-bundle-load-from-memory", elapsed); + return loaded; } private byte[] ReadVerifiedArtifactBytes(CultMeshCdnArtifactManifest manifest) diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs index 64a7ef1..702c142 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/CultMesh/EveUnityCultMeshPlayableWorldProvider.cs @@ -3,6 +3,7 @@ using System.IO; using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading.Tasks; +using Stopwatch = System.Diagnostics.Stopwatch; using GameCult.Eve.Surface; using GameCult.Eve.PluginFields; using GameCult.Eve.UnityScene.Fields; @@ -203,6 +204,7 @@ namespace GameCult.Eve.UnityScene private async Task PrepareTransportAsync() { + var elapsed = Stopwatch.StartNew(); if (_transport != null) return; if (string.IsNullOrWhiteSpace(rendezvousEndpoint)) @@ -214,6 +216,8 @@ namespace GameCult.Eve.UnityScene surfaceFilter, surfaceKind, verseFilter); + TraceStartup($"discovery {elapsed.Elapsed.TotalMilliseconds:0.###}ms"); + elapsed.Restart(); var resolvedReplicaPath = string.IsNullOrWhiteSpace(replicaPath) ? Path.Combine(Application.temporaryCachePath, $"eve-unity-{GetInstanceID()}.cc") : replicaPath; @@ -226,6 +230,13 @@ namespace GameCult.Eve.UnityScene _transport.EntityViewAvailable += (view, lease) => _pendingEntityViews.Enqueue(new EntityViewLease(view, lease)); _transport.FieldsSplatsAvailable += fields => _pendingFields.Enqueue(fields); _bridge = new EveUnitySceneLiveProviderBridge(_transport); + TraceStartup($"transport-construction {elapsed.Elapsed.TotalMilliseconds:0.###}ms"); + } + + private static void TraceStartup(string message) + { + if (string.Equals(Environment.GetEnvironmentVariable("EVEUNITY_TRACE_STARTUP_PHASES"), "1", StringComparison.Ordinal)) + Debug.Log($"EveUnity startup phase {message}."); } private void RequirePrepared() diff --git a/packages/org.gamecult.eve.unity-scene/package.json b/packages/org.gamecult.eve.unity-scene/package.json index d667c4b..d8f8df3 100644 --- a/packages/org.gamecult.eve.unity-scene/package.json +++ b/packages/org.gamecult.eve.unity-scene/package.json @@ -1,11 +1,11 @@ { "name": "org.gamecult.eve.unity-scene", "displayName": "Eve Unity Scene Lowering", - "version": "0.3.94", + "version": "0.3.95", "unity": "6000.0", "description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.", "dependencies": { - "org.gamecult.cultlib": "1.0.34", + "org.gamecult.cultlib": "1.0.35", "org.gamecult.eve.plugin-fields": "0.2.3", "org.gamecult.eve.surface": "0.2.4", "com.unity.mathematics": "1.3.2", diff --git a/scripts/run-aetheria-daemon-world-witness.ps1 b/scripts/run-aetheria-daemon-world-witness.ps1 index ba440ab..b9bb925 100644 --- a/scripts/run-aetheria-daemon-world-witness.ps1 +++ b/scripts/run-aetheria-daemon-world-witness.ps1 @@ -208,6 +208,7 @@ $daemonArguments = @( ) $env:AETHERIA_TRACE_EVE_SNAPSHOTS = "1" $env:AETHERIA_TRACE_CLIENT_TRANSPORT = "1" +$env:AETHERIA_TRACE_STARTUP_PHASES = "1" $env:EVEUNITY_RENDEZVOUS_ENDPOINT = "cultnet+tcp://127.0.0.1:$Port" $env:EVEUNITY_PROVIDER_ID = "aetheria" Remove-Item Env:EVEUNITY_SURFACE_ID -ErrorAction SilentlyContinue @@ -220,6 +221,7 @@ $env:EVEUNITY_WITNESS_FACTS_PATH = $factsPath $env:EVEUNITY_PROVIDER_READY_PATH = $providerReadyPath $env:EVEUNITY_WITNESS_PROFILE = $witnessProfile $env:EVEUNITY_WITNESS_GAMEPLAY_SCENARIO = $GameplayScenario +$env:EVEUNITY_TRACE_STARTUP_PHASES = "1" $arguments = @( "-batchmode", "-projectPath", $projectRoot, "-runTests", "-testPlatform", "PlayMode",