Optimize GC for RMV pool.

This commit is contained in:
2023-01-01 19:03:19 +08:00
parent cf6186aa16
commit 2b5bc5dd08
2 changed files with 6 additions and 2 deletions

View File

@@ -219,7 +219,7 @@ namespace Cryville.Crtr.Event {
if (!CachedValues.TryGetValue(key, out tr))
CachedValues.Add(key, tr = new CacheEntry { Valid = false });
if (tr.Value == null)
tr.Value = (Vector)ReflectionHelper.InvokeEmptyConstructor(ChartPlayer.motionRegistry[key].Type);
tr.Value = RMVPool.Rent(key).AbsoluteValue;
Vector r = tr.Value;
#if !DISABLE_CACHE
if (tr.Valid) return r;

View File

@@ -20,10 +20,13 @@ namespace Cryville.Crtr.Event {
_buckets.Add(reg.Key, new Bucket(reg.Key, 4096));
}
readonly Dictionary<RealtimeMotionValue, Identifier> _rented = new Dictionary<RealtimeMotionValue, Identifier>();
static readonly SimpleObjectPool<Dictionary<RealtimeMotionValue, Identifier>> _dictPool
= new SimpleObjectPool<Dictionary<RealtimeMotionValue, Identifier>>(1024);
Dictionary<RealtimeMotionValue, Identifier> _rented;
public RealtimeMotionValue Rent(Identifier name) {
var n = name;
var obj = _buckets[n].Rent();
if (_rented == null) _rented = _dictPool.Rent();
_rented.Add(obj, n);
return obj;
}
@@ -35,6 +38,7 @@ namespace Cryville.Crtr.Event {
foreach (var obj in _rented)
_buckets[obj.Value].Return(obj.Key);
_rented.Clear();
_dictPool.Return(_rented);
}
}
}