From 9a223159e5ed67484bb6f251c3d6808a416566e2 Mon Sep 17 00:00:00 2001 From: austin Date: Sun, 25 May 2025 15:49:05 -0400 Subject: [PATCH] performance work --- docs/src/progress/renderertodo.md | 1 + .../data/utils/DataFormatUtil.java | 8 ++--- .../entity/state/attach/AttachUtils.java | 3 +- .../state/hitbox/HitboxCollectionState.java | 10 ++---- src/main/java/electrosphere/mem/JomlPool.java | 35 ------------------- .../electrosphere/renderer/actor/Actor.java | 2 +- 6 files changed, 8 insertions(+), 51 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 3b607df6..4525b84a 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1989,6 +1989,7 @@ Performance improvements - Shallow clone on physics cell creation - More vector pool usage - Model anim calculations no longer allocate new matrix4d's + - Undo most object pooling Increase human move speed LOD components re-attach physics VectorPool->JomlPool diff --git a/src/main/java/electrosphere/data/utils/DataFormatUtil.java b/src/main/java/electrosphere/data/utils/DataFormatUtil.java index 7f142bd6..37cab40c 100644 --- a/src/main/java/electrosphere/data/utils/DataFormatUtil.java +++ b/src/main/java/electrosphere/data/utils/DataFormatUtil.java @@ -6,8 +6,6 @@ import java.util.List; import org.joml.Quaterniond; import org.joml.Vector3d; -import electrosphere.mem.JomlPool; - /** * Converts data structures between formats saved to disk vs formats used in engine */ @@ -45,12 +43,12 @@ public class DataFormatUtil { */ public static Vector3d getDoubleListAsVector(List values){ if(values == null){ - return JomlPool.getD(); + return new Vector3d(); } if(values.size() > 0){ - return JomlPool.getD(values.get(0),values.get(1),values.get(2)); + return new Vector3d(values.get(0),values.get(1),values.get(2)); } else { - return JomlPool.getD(); + return new Vector3d(); } } diff --git a/src/main/java/electrosphere/entity/state/attach/AttachUtils.java b/src/main/java/electrosphere/entity/state/attach/AttachUtils.java index 99285cd4..babff618 100644 --- a/src/main/java/electrosphere/entity/state/attach/AttachUtils.java +++ b/src/main/java/electrosphere/entity/state/attach/AttachUtils.java @@ -6,7 +6,6 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; import electrosphere.logger.LoggerInterface; -import electrosphere.mem.JomlPool; import electrosphere.renderer.actor.Actor; import electrosphere.server.datacell.ServerDataCell; import electrosphere.server.datacell.utils.ServerEntityTagUtils; @@ -347,7 +346,7 @@ public class AttachUtils { Vector3d parentScale ){ //transform bone space - Vector3d position = JomlPool.getD(offsetVector); + Vector3d position = new Vector3d(offsetVector); position = position.rotate(new Quaterniond(boneRotation)); position = position.add(bonePosition); position = position.mul(parentScale); diff --git a/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java b/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java index 0650e5cb..e2ce1ea1 100644 --- a/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java +++ b/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java @@ -26,7 +26,6 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.state.attach.AttachUtils; import electrosphere.entity.state.hitbox.HitboxCollectionState.HitboxState.HitboxShapeType; import electrosphere.logger.LoggerInterface; -import electrosphere.mem.JomlPool; import electrosphere.server.datacell.Realm; import electrosphere.server.entity.poseactor.PoseActor; import electrosphere.util.math.SpatialMathUtils; @@ -462,7 +461,7 @@ public class HitboxCollectionState { Quaterniond offsetRotation = new Quaterniond(); //the bone's transform - Vector3d bonePositionD = JomlPool.getD(); + Vector3d bonePositionD = new Vector3d(); if(bonePosition != null){ bonePositionD.set(bonePosition); } @@ -471,7 +470,7 @@ public class HitboxCollectionState { //the parent's transform Vector3d parentPosition = EntityUtils.getPosition(parent); Quaterniond parentRotation = EntityUtils.getRotation(parent); - Vector3d parentScale = JomlPool.getD(); + Vector3d parentScale = new Vector3d(); parentScale.set(EntityUtils.getScale(parent)); //calculate @@ -480,11 +479,6 @@ public class HitboxCollectionState { //actually set value PhysicsEntityUtils.setGeometryOffsetPosition(collisionEngine, geom, hitboxPos, new Quaterniond()); - - //free vecs used in computation - JomlPool.release(bonePositionD); - JomlPool.release(parentScale); - JomlPool.release(hitboxPos); } /** diff --git a/src/main/java/electrosphere/mem/JomlPool.java b/src/main/java/electrosphere/mem/JomlPool.java index 5432188b..babaa1d6 100644 --- a/src/main/java/electrosphere/mem/JomlPool.java +++ b/src/main/java/electrosphere/mem/JomlPool.java @@ -73,41 +73,6 @@ public class JomlPool { return rVal; } - /** - * Gets a Vector3d from the pool. Allocates if no free one is available. - * @param source The source to copy from - * @return A Vector3d - */ - public static Vector3d getD(Vector3d source){ - Vector3d rVal = null; - lock.lock(); - if(vec3dPool.size() > 0){ - rVal = vec3dPool.remove(0); - } else { - rVal = new Vector3d(); - } - rVal.set(source); - lock.unlock(); - return rVal; - } - - /** - * Gets a Vector3d from the pool. Allocates if no free one is available. - * @return A Vector3d - */ - public static Vector3d getD(double x, double y, double z){ - Vector3d rVal = null; - lock.lock(); - if(vec3dPool.size() > 0){ - rVal = vec3dPool.remove(0); - } else { - rVal = new Vector3d(); - } - rVal.set(x,y,z); - lock.unlock(); - return rVal; - } - /** * Releases a Vector3d back into the pool * @param data The object to release diff --git a/src/main/java/electrosphere/renderer/actor/Actor.java b/src/main/java/electrosphere/renderer/actor/Actor.java index 823a85ef..3a70df15 100644 --- a/src/main/java/electrosphere/renderer/actor/Actor.java +++ b/src/main/java/electrosphere/renderer/actor/Actor.java @@ -887,7 +887,7 @@ public class Actor { } Globals.profiler.beginAggregateCpuSample("Actor.isWithinFrustumBox"); Sphered sphere = model.getBoundingSphere(); - Vector3d modelPosition = model.getModelMatrix().getTranslation(JomlPool.getD()); + Vector3d modelPosition = model.getModelMatrix().getTranslation(new Vector3d()); boolean check = renderPipelineState.getFrustumIntersection().testSphere((float)(sphere.x + modelPosition.x), (float)(sphere.y + modelPosition.y), (float)(sphere.z + modelPosition.z), (float)sphere.r); JomlPool.release(modelPosition); Globals.profiler.endCpuSample();