Optimize GC for RMV pool.
This commit is contained in:
@@ -219,7 +219,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
if (!CachedValues.TryGetValue(key, out tr))
|
if (!CachedValues.TryGetValue(key, out tr))
|
||||||
CachedValues.Add(key, tr = new CacheEntry { Valid = false });
|
CachedValues.Add(key, tr = new CacheEntry { Valid = false });
|
||||||
if (tr.Value == null)
|
if (tr.Value == null)
|
||||||
tr.Value = (Vector)ReflectionHelper.InvokeEmptyConstructor(ChartPlayer.motionRegistry[key].Type);
|
tr.Value = RMVPool.Rent(key).AbsoluteValue;
|
||||||
Vector r = tr.Value;
|
Vector r = tr.Value;
|
||||||
#if !DISABLE_CACHE
|
#if !DISABLE_CACHE
|
||||||
if (tr.Valid) return r;
|
if (tr.Valid) return r;
|
||||||
|
|||||||
@@ -20,10 +20,13 @@ namespace Cryville.Crtr.Event {
|
|||||||
_buckets.Add(reg.Key, new Bucket(reg.Key, 4096));
|
_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) {
|
public RealtimeMotionValue Rent(Identifier name) {
|
||||||
var n = name;
|
var n = name;
|
||||||
var obj = _buckets[n].Rent();
|
var obj = _buckets[n].Rent();
|
||||||
|
if (_rented == null) _rented = _dictPool.Rent();
|
||||||
_rented.Add(obj, n);
|
_rented.Add(obj, n);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@@ -35,6 +38,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
foreach (var obj in _rented)
|
foreach (var obj in _rented)
|
||||||
_buckets[obj.Value].Return(obj.Key);
|
_buckets[obj.Value].Return(obj.Key);
|
||||||
_rented.Clear();
|
_rented.Clear();
|
||||||
|
_dictPool.Return(_rented);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user