Parallel batch loading + PrefabIndex + dynamic batch size#2
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces sequential one-by-one asset-bundle scanning with parallel batched loading, a lightweight prefab-name index, and several performance optimizations.
Changes (5 files, code only)
Parallel bundle loading (CarBuilder.cs — modified)
The core loading method was rewritten to support parallel batch processing:
ThreadPool.QueueUserWorkItemloads bundles in parallel, synchronized viaManualResetEvent. Overlaps disk I/O across bundles.Math.Max(2, Environment.ProcessorCount)replaces the old hardcoded4. Adapts to each user's core count automatically.UnityFS/UnityRaw/UnityWebheaders before callingAssetBundle.LoadFromFile. Rejects non-bundles in microseconds instead of timing out.bundle.Unload(false)after extracting prefabs, freeing compressed data while keeping loaded GameObjects valid.renderer.materialscaptured once into a local variable instead of accessed repeatedly (avoided per-iteration array allocation).Prefab name index (PrefabIndex.cs — NEW, ~120 lines)
A lightweight JSON index that avoids the expensive
GetAllAssetNames()call for unchanged files:File.GetLastWriteTimeUtcticks. If unchanged, prefab names are read from the index;GetAllAssetNames()is skipped entirely.Settings/prefab_index.jsonvia JsonFx (same serializer already used by the project).Much simpler than the previous CarCache approach — no signature hashing, no invalid-file tracking, no combined hash. Just a cached list of prefab names per file.
Assets.cs — cached reflection
AssetBundleBridge.AssetBundleTypewas callingKernel.FindTypeByFullName()on every access (247+ times). The type andMethodInfoare now resolved once in the static constructor. The"Loaded asset bundle"log was also removed.Section.cs + DictionaryExtensions.cs — factory overload for GetOrCreate
GetOrCreate<T>(string key, Func<T> factory)avoids allocating the default value when the key already exists. The extension method onDictionary<string, object>mirrors theSectioninstance method.ProfileCarColors.cs — use factory overload + cleanup
Switched all three
GetOrCreatecalls to the factory overload. Removed twoLogInfomessages ("Assigning Profile Name...","Assigning Vehicle Name...") that produced 500+ log lines at startup.