feat: Adds new decay system and SkipSerialization (#2311)

## Summary

- Replaces scan-based decay checking during world saves with an event-driven timer wheel scheduler
- Removes virtual property checks from serialization hot path, achieving 6-8x faster world saves

## Changes

### DecayScheduler (new):
- Timer wheel with 12 HashSet buckets (5-min intervals) + PriorityQueue for active processing
- O(1) register/unregister vs O(n) scan of all items
- Auto start/stop when items exist/empty
- Configurable tick interval with jitter to prevent system synchronization

### Item.cs:
- Added ScheduledDecayTime computed property
- Added UpdateDecayRegistration() called from SetLastMoved(), property setters, AddItem()/RemoveItem()
- Hooks in Visible, Movable, Spawner setters and Delete()

### World.cs:
- Removed _decayQueue, EnqueueForDecay(), ProcessDecay()
- ItemPersistence.Serialize() now tight loop without virtual calls

## Performance

| Metric        | Before     | After     | Improvement |
|---------------|------------|-----------|-------------|
| Items (230K)  | 245K ticks | 34K ticks | 8x faster   |
| Mobiles (43K) | 56K ticks  | 6K ticks  | 9x faster   |
| Total         | 302K ticks | 40K ticks | 7.5x faster |

## Configuration

decay.maxItemsPerTick = 250       # Items processed per tick
decay.tickInterval = 256ms        # Base processing interval
decay.bucketInterval = 5min       # Timer wheel bucket size
decay.jitterMaxMs = 25            # ±25ms tick jitter
This commit is contained in:
Kamron Batman 2026-01-08 11:43:51 -08:00 • committed by GitHub
parent c14f361de1
commit ee2cd1d18d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 426 additions and 173 deletions

View file

@ -901,6 +901,8 @@ public partial class TreasureChestDirt : Item
Timer.StartTimer(TimeSpan.FromMinutes(2.0), Delete);
}
public override bool SkipSerialization => true;
public void Turn1()
{
ItemID = 0x913;
@ -910,10 +912,4 @@ public partial class TreasureChestDirt : Item
{
ItemID = 0x914;
}
[AfterDeserialization(false)]
private void AfterDeserialization()
{
Delete();
}
}

View file

@ -39,6 +39,8 @@ public partial class Acid : Item
public override string DefaultName => "a pool of acid";
public override bool SkipSerialization => true;
public override void OnDelete()
{
_timerToken.Cancel();
@ -89,10 +91,4 @@ public partial class Acid : Item
{
m.Damage(Utility.RandomMinMax(_minDamage, _maxDamage));
}
[AfterDeserialization(false)]
private void AfterDeserialization()
{
Delete();
}
}

View file

@ -15,6 +15,8 @@ public partial class EffectItem : Item
public override bool Decays => true;
public override bool SkipSerialization => true;
public static EffectItem Create(Point3D p, Map map, TimeSpan duration)
{
EffectItem item = null;
@ -46,12 +48,6 @@ public partial class EffectItem : Item
public void BeginFree(TimeSpan duration) => new FreeTimer(this, duration).Start();
[AfterDeserialization(false)]
private void AfterDeserialization()
{
Delete();
}
private class FreeTimer : Timer
{
private EffectItem _item;

View file

@ -21,6 +21,8 @@ public partial class MoonstoneGate : Moongate
Effects.PlaySound(loc, map, 0x20E);
}
public override bool SkipSerialization => true;
public override void CheckGate(Mobile m, int range)
{
if (m.Kills >= 5)
@ -53,12 +55,6 @@ public partial class MoonstoneGate : Moongate
}
}
[AfterDeserialization(false)]
private void AfterDeserialization()
{
Delete();
}
private class InternalTimer : Timer
{
private Item _item;

View file

@ -32,6 +32,8 @@ public partial class Campfire : Item
Timer.StartTimer(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), OnTick, out _timerToken);
}
public override bool SkipSerialization => true;
[CommandProperty(AccessLevel.GameMaster)]
public CampfireStatus Status
{
@ -159,12 +161,6 @@ public partial class Campfire : Item
_timerToken.Cancel();
ClearEntries();
}
[AfterDeserialization(false)]
private void AfterDeserialization()
{
Delete();
}
}
public class CampfireEntry

View file

@ -14,6 +14,8 @@ namespace Server.Items
Quality = WeaponQuality.Regular;
}
public override bool SkipSerialization => true;
public override WeaponAbility PrimaryAbility => WeaponAbility.Disarm;
public override WeaponAbility SecondaryAbility => WeaponAbility.ParalyzingBlow;
@ -169,12 +171,6 @@ namespace Server.Items
base.PlaySwingAnimation( attacker );
}*/
[AfterDeserialization(false)]
private void OnAfterDeserialization()
{
Delete();
}
/* Wrestling moves */
private static bool CheckMove(Mobile m, SkillName other)