mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-19 06:32:03 +01:00
Fix entity memory leak, improve entity collection creation performance
This commit is contained in:
parent
136ed17c0b
commit
555cdb66de
@ -164,20 +164,19 @@ public abstract class ThreadProvider {
|
|||||||
public synchronized @NotNull CountDownLatch update(long time) {
|
public synchronized @NotNull CountDownLatch update(long time) {
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(threads.size());
|
CountDownLatch countDownLatch = new CountDownLatch(threads.size());
|
||||||
for (TickThread thread : threads) {
|
for (TickThread thread : threads) {
|
||||||
final var chunkEntries = threadChunkMap.get(thread);
|
|
||||||
if (chunkEntries == null || chunkEntries.isEmpty()) {
|
|
||||||
// The thread never had any task
|
|
||||||
countDownLatch.countDown();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute tick
|
// Execute tick
|
||||||
thread.runnable.startTick(countDownLatch, () -> {
|
thread.runnable.startTick(countDownLatch, () -> {
|
||||||
final var entitiesList = chunkEntries.stream().map(chunkEntry -> chunkEntry.entities).collect(Collectors.toList());
|
final var chunkEntries = threadChunkMap.get(thread);
|
||||||
final var entities = entitiesList.stream()
|
if (chunkEntries == null || chunkEntries.isEmpty()) {
|
||||||
.flatMap(Collection::stream)
|
// Nothing to tick
|
||||||
.collect(Collectors.toList());
|
AcquirableEntity.refresh(Collections.emptyList());
|
||||||
AcquirableEntity.refresh(Collections.unmodifiableList(entities));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final var entities = chunkEntries.stream()
|
||||||
|
.flatMap(chunkEntry -> chunkEntry.entities.stream())
|
||||||
|
.collect(Collectors.toUnmodifiableList());
|
||||||
|
AcquirableEntity.refresh(entities);
|
||||||
|
|
||||||
final ReentrantLock lock = thread.getLock();
|
final ReentrantLock lock = thread.getLock();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
|
Loading…
Reference in New Issue
Block a user