ModernUO/Projects/Server/Guild.cs
Kamron Batman 3b75b96008
perf(saves): drop the 9-byte per-entity placement state; write snapshots from worker segment logs
Every ISerializable carried SerializedThread/SerializedPosition/SerializedLength
so WriteSnapshot could gather each entity's bytes from the worker heaps in
dictionary order. The idx records absolute positions, so bin order is free -
the snapshot can be written in worker-heap order instead, and the join inverts:

- Chunks are persistence-homogeneous: SerializeAll declares the owner at each
  boundary, publishing the partial chunk on change.
- Workers log segments (owner, slot range, heap start) plus one length per
  record as they serialize. Positions are implicit because a worker's writes
  are contiguous; identity comes from re-walking the same snapshot slots in
  the same order (guaranteed stable - mutations divert to the pending queues
  until PostWorldSave), or from an entities log on the fallback path.
- WriteSnapshot routes segments by owner, emits idx entries during the
  re-walk, and writes each segment's heap bytes as a single span instead of
  one copy per entity, which also speeds up the background write phase.
- Persistence self-payloads keep placement as three private fields on the
  ~dozens of persistence instances; PushSingle is now typed accordingly.

Net effect: 9 bytes (plus padding) of resident state removed from every item,
mobile, guild, and account on every shard; three interface-property stores
per entity leave the drain hot path (stamping dirtied one cache line per
entity mid-freeze - the lengths log is a single sequential stream); and the
vestigial loader-side length stamp is gone. The transient cost is ~4 bytes
per entity in pooled per-worker logs that are released after each write.

The save format is unchanged (idx v3, same loader); only the write-side
mechanics moved. Adds an end-to-end round-trip test that drives real workers
through the chunk source, snapshots from the segment logs, and reloads.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 22:38:47 -07:00

126 lines
3.5 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2026 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Guild.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
using System.Collections.Generic;
namespace Server.Guilds;
public enum GuildType
{
Regular,
Chaos,
Order
}
public abstract class BaseGuild : ISerializable
{
protected BaseGuild()
{
Serial = World.NewGuild;
World.AddGuild(this);
}
protected BaseGuild(Serial serial) => Serial = serial;
public abstract string Abbreviation { get; set; }
public abstract string Name { get; set; }
public abstract GuildType Type { get; set; }
public abstract bool Disbanded { get; }
public abstract void Delete();
public bool Deleted => Disbanded;
[IgnoreDupe]
[CommandProperty(AccessLevel.Counselor)]
public Serial Serial { get; }
[IgnoreDupe]
[CommandProperty(AccessLevel.GameMaster, readOnly: true)]
public DateTime Created { get; set; } = Core.Now;
public abstract void Serialize(IGenericWriter writer);
public abstract void Deserialize(IGenericReader reader);
public abstract void OnDelete(Mobile mob);
public static BaseGuild FindByName(ReadOnlySpan<char> name)
{
foreach (var g in World.Guilds.Values)
{
if (g.Name.InsensitiveEquals(name))
{
return g;
}
}
return null;
}
public static BaseGuild FindByAbbrev(ReadOnlySpan<char> abbr)
{
foreach (var g in World.Guilds.Values)
{
if (g.Abbreviation.InsensitiveEquals(abbr))
{
return g;
}
}
return null;
}
public static HashSet<BaseGuild> Search(ReadOnlySpan<char> find)
{
var results = new HashSet<BaseGuild>();
find = find.Trim();
if (find.IsEmpty)
{
return results;
}
foreach (var g in World.Guilds.Values)
{
var name = g.Name.AsSpan();
var all = true;
foreach (var wordRange in find.Split(' '))
{
var word = find[wordRange];
if (word.IsEmpty)
{
continue;
}
if (name.InsensitiveContains(word))
{
all = false;
break;
}
}
if (all)
{
results.Add(g);
}
}
return results;
}
public override string ToString() => $"{Serial} \"{Name} [{Abbreviation}]\"";
}