Description
I practiced a AssetsTools.NET helloworld by dumping an assets list, but found it slower than expectation.
A minimal loop like this could end up in pretty bad performance.
foreach (var assetInfo in assetsFile.table.assetFileInfo) {
var dummy = assetsManager.GetTypeInstance(assetsFile, assetInfo);
}
Some performance numbers:
(Linux/Mono 5.15.0/6.12; i7-8809G/kabylake 3.1-4.2G)
(Resources size: around 4GiB, 64k assets)
With the loop above: ~20s
Remove loop, skip AssetsManager.GetTypeInstance(): < 2s
Sequence read of assets file: < 0.5s (fully cached)
According to mono profiler:
85% time is consumed in unmanaged code.
GC took 2/3 of the 85% unmanaged time. (I would guess that most of the rest is allocation)
Allocation count is high, near 30M when I killed the run.
Top-down allocation (IMO bytes doesn't matter, count dominates).
Allocation summary
Bytes Count Average Type name
178768656 3724347 48 AssetsTools.NET.AssetTypeValueField
169192824 2643434 64 System.Char[]
147427880 3676029 40 AssetsTools.NET.AssetTypeValueField[]
138437568 3840063 36 System.String
129897912 54316 2391 System.Byte[]
126876768 2643266 48 System.Text.StringBuilder
89752352 2804761 32 AssetsTools.NET.AssetTypeValue
76334176 28707 2659 AssetsTools.NET.ClassDatabaseTypeField[]
71313368 1273453 56 AssetsTools.NET.AssetTypeTemplateField
51226184 1282455 39 AssetsTools.NET.AssetTypeTemplateField[]
50938120 1273453 40 System.Collections.Generic.List<System.Int32>
44710440 1862935 24 System.Int32
29761104 1240046 24 System.Single
27338816 507606 53 System.Int32[]
19587816 816159 24 System.Byte
15064728 627697 24 System.Int64
10482720 436780 24 AssetsTools.NET.AssetTypeArray
6289536 98274 64 AssetsTools.NET.AssetFileInfoEx
5592720 233030 24 System.UInt32
3848256 160344 24 System.SByte
(Use mode=throughput is about 5-10% faster and situation does not really change)
Is it possible to reduce objects count? (I guess most of them will be persistent?)
With so many objects, proceeding GC could also be slow.