SBP缓存问题

/ 0评 / 0

Unity官网也有用户反馈相关问题Building is very slow and build cache grows dramatically,官方说1.7.0版本已经修复了。

不过今天2021/03/24发现,到现在为止Unity的Package Manager中最新版本ScriptableBuildPipeline - v1.17.0缓存依然有问题。

主要问题在IBuildCache接口中多个GetCacheEntry方法的version参数和BuildCacheUtility中几个GetCacheEntry方法的version参数,被Selectversion会被传递成遍历index


public static void GatherSerializedObjectCacheEntries(this WriteCommand command, HashSet<CacheEntry> cacheEntries)
{
    if (command.serializeObjects != null)
    {
        var objectIds = command.serializeObjects.Select(x => x.serializationObject);
        var types = BuildCacheUtility.GetSortedUniqueTypesForObjects(objectIds);
        // 问题在这里 Select 后GetCacheEntry的version参数一直变化,缓存??
        cacheEntries.UnionWith(types.Select(BuildCacheUtility.GetCacheEntry));
        cacheEntries.UnionWith(objectIds.Select(BuildCacheUtility.GetCacheEntry));
    }
}

CacheEntry GetCacheEntry(GUID asset, int version = 1);

CacheEntry GetCacheEntry(string path, int version = 1);

CacheEntry GetCacheEntry(ObjectIdentifier objectID, int version = 1);

CacheEntry GetCacheEntry(Type type, int version = 1);

public static CacheEntry GetCacheEntry(string path, int version = 1)
{
    CacheEntry entry;
    KeyValuePair<string, int> key = new KeyValuePair<string, int>(path, version);
    if (m_PathToHash.TryGetValue(key, out entry))
        return entry;

    var guid = AssetDatabase.AssetPathToGUID(path);
    if (!string.IsNullOrEmpty(guid))
        return GetCacheEntry(new GUID(guid), version);

    entry = new CacheEntry { File = path, Version = version };
    entry.Guid = HashingMethods.Calculate("FileHash", entry.File).ToGUID();
    if (File.Exists(entry.File))
        entry.Hash = HashingMethods.Calculate(HashingMethods.CalculateFile(entry.File), entry.Version).ToHash128();
    entry.Type = CacheEntry.EntryType.File;

    m_PathToHash[key] = entry;
    return entry;
}

public static CacheEntry GetCacheEntry(Type type, int version = 1)
{
    CacheEntry entry;
    KeyValuePair<string, int> key = new KeyValuePair<string, int>(type.AssemblyQualifiedName, version);
    if (m_TypeToHash.TryGetValue(key, out entry))
        return entry;

    entry = new CacheEntry { ScriptType = type.AssemblyQualifiedName, Version = version };
    entry.Guid = HashingMethods.Calculate("TypeHash", entry.ScriptType).ToGUID();
#if ENABLE_TYPE_HASHING
    entry.Hash = ContentBuildInterface.CalculatePlayerSerializationHashForType(type, m_TypeDB);
#else
    entry.Hash = m_TypeDB != null ? m_TypeDB.GetHash128() : m_UnityVersion;
#endif
    entry.Type = CacheEntry.EntryType.ScriptType;
    // simon: 原版这里也有错误
    // m_PathToHash[key] = entry;
    m_TypeToHash[key] = entry;
    return entry;
}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注