Skip to content

Commit

Permalink
Drop debug allocs a lot (#5638)
Browse files Browse the repository at this point in the history
IDK why the lifestage one in particular ballooned my dotmemory one up in particular but it did; I would've thought if it's boxing the other ones would've shown up. Doesn't matter for release just QOL to drop allocs by more than half.
  • Loading branch information
metalgearsloth authored Jan 30, 2025
1 parent 2b2d08b commit 4364820
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Robust.Server/GameStates/PvsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ namespace Robust.Server.GameStates;
/// </summary>
internal sealed class PvsSession(ICommonSession session, ResizableMemoryRegion<PvsData> memoryRegion)
{
#if DEBUG
public HashSet<NetEntity> ToSendSet = new();
#endif

public readonly ICommonSession Session = session;

public readonly ResizableMemoryRegion<PvsData> DataMemory = memoryRegion;
Expand Down Expand Up @@ -197,7 +201,7 @@ public void Validate(MetaDataComponent comp)
{
DebugTools.AssertEqual(NetEntity, comp.NetEntity);
DebugTools.AssertEqual(VisMask, comp.VisibilityMask);
DebugTools.AssertEqual(LifeStage, comp.EntityLifeStage);
DebugTools.Assert(LifeStage == comp.EntityLifeStage);
DebugTools.Assert(LastModifiedTick == comp.EntityLastModifiedTick || LastModifiedTick.Value == 0);
}
}
Expand Down
10 changes: 7 additions & 3 deletions Robust.Server/GameStates/PvsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ private void GetEntityStates(PvsSession session)
// Process all entities in visible PVS chunks
AddPvsChunks(session);

#if DEBUG
VerifySessionData(session);
#endif

var toSend = session.ToSend!;
session.ToSend = null;
Expand Down Expand Up @@ -332,11 +334,12 @@ private void GetEntityStates(PvsSession session)
session.Overflow = oldEntry.Value;
}

[Conditional("DEBUG")]
#if DEBUG
private void VerifySessionData(PvsSession pvsSession)
{
var toSend = pvsSession.ToSend;
var toSendSet = new HashSet<NetEntity>(toSend!.Count);
var toSend = pvsSession.ToSend!;
var toSendSet = pvsSession.ToSendSet;
toSendSet.Clear();

foreach (var intPtr in toSend)
{
Expand All @@ -360,6 +363,7 @@ private void VerifySessionData(PvsSession pvsSession)
|| data.LastSeen == _gameTiming.CurTick - 1);
}
}
#endif

private (Vector2 worldPos, float range, EntityUid? map) CalcViewBounds(Entity<TransformComponent, EyeComponent?> eye)
{
Expand Down

0 comments on commit 4364820

Please sign in to comment.