[SPIGOT-1384] Entity#a(AxisAlignedBB) creates new object Created: 31/Dec/15  Updated: 06/Feb/22

Status: In Progress
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Michael Zangl Assignee: md_5
Resolution: Unresolved Votes: 1
Labels: Craftbukkit

Attachments: HTML File entity-aabb-patch    

 Description   

Entity#a(AxisAlignedBB) attempts to fix the AABB given to it. This forces the cretaion of a new AABB every time the method is invoked (which is quite often).

This patch skips many AABB allocations on my test server and reduced their allocation count by 16% (many entities on that server)

public void a(AxisAlignedBB axisalignedbb) {
// Changes start - block invalid bounding boxes
// Fix: Do not allocate if not required.
double a = axisalignedbb.a,
b = axisalignedbb.b,
c = axisalignedbb.c,
d = axisalignedbb.d,
e = axisalignedbb.e,
f = axisalignedbb.f;
if (d - a > 64 || d - a < 0 || e - b > 64 || e - b < 0 || f - c > 64 || f - c < 0)

{ // This should rarely happen! assignFixedAABB(a, b, c, d, e, f); }

else

{ this.boundingBox = axisalignedbb; }

// Changes end
}

// Changes start - block invalid bounding boxes
private void assignFixedAABB(double a, double b, double c, double d, double e,
double f)

{ d = clamp(d, a, a + 64); e = clamp(e, b, b+64); f = clamp(f, c, c+64); this.boundingBox = new AxisAlignedBB(a, b, c, d, e, f); }

private double clamp(double d, double min, double max)

{ if (d < min) return min; if (d > max) return max; return d; }

// Changes end



 Comments   
Comment by RyanTheLeach [ 06/Feb/22 ]

without performance profiling this could probably be closed. 

 

My best guess for what this method is (in 2022) is that it was named SetBoundingBox

 

I don't think that making a defensive copy, with some sanity checks is that big of a deal.

Comment by md_5 [ 03/Jan/16 ]

CLA as per other tickets.

Generated at Tue Apr 22 05:44:26 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.