Skip to content

Commit 149e9c5

Browse files
authored
perf(render): specialize singleton display spawns (#65)
Validated by paired GitHub JMH A/B run 29478305028 (PASS_OPTIMIZED, 8/8 wins for time and allocation).
1 parent 30e2386 commit 149e9c5

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/main/java/top/ellan/mahjong/render/display/DisplayEntities.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public static List<Entity> spawnAll(DisplayEntityRuntime runtime, List<EntitySpe
126126
return List.of();
127127
}
128128
DisplayEntityRuntime scopedRuntime = visibilitySnapshotRuntime(runtime);
129+
if (specs.size() == 1) {
130+
Entity entity = specs.get(0).spawn(scopedRuntime);
131+
return entity == null ? List.of() : List.of(entity);
132+
}
129133
List<Entity> spawned = new java.util.ArrayList<>(specs.size());
130134
for (EntitySpec spec : specs) {
131135
Entity entity = spec.spawn(scopedRuntime);

0 commit comments

Comments
 (0)