mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-29 04:28:21 +01:00
Use a parallel stream for viewable packets
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
c0024fe4dd
commit
b5b281c717
@ -47,7 +47,6 @@ public final class PacketUtils {
|
||||
private static final LocalCache<ByteBuffer> LOCAL_BUFFER = LocalCache.ofBuffer(Server.MAX_PACKET_SIZE);
|
||||
|
||||
// Viewable packets
|
||||
private static final Object VIEWABLE_PACKET_LOCK = new Object();
|
||||
private static final Map<Viewable, ViewableStorage> VIEWABLE_STORAGE_MAP = new WeakHashMap<>();
|
||||
|
||||
private PacketUtils() {
|
||||
@ -155,7 +154,7 @@ public final class PacketUtils {
|
||||
return;
|
||||
}
|
||||
ViewableStorage viewableStorage;
|
||||
synchronized (VIEWABLE_PACKET_LOCK) {
|
||||
synchronized (VIEWABLE_STORAGE_MAP) {
|
||||
viewableStorage = VIEWABLE_STORAGE_MAP.computeIfAbsent(viewable, ViewableStorage::new);
|
||||
}
|
||||
viewableStorage.append(serverPacket, player != null ? player.getPlayerConnection() : null);
|
||||
@ -168,10 +167,9 @@ public final class PacketUtils {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void flush() {
|
||||
synchronized (VIEWABLE_PACKET_LOCK) {
|
||||
for (ViewableStorage viewableStorage : VIEWABLE_STORAGE_MAP.values()) {
|
||||
viewableStorage.process(null);
|
||||
}
|
||||
synchronized (VIEWABLE_STORAGE_MAP) {
|
||||
VIEWABLE_STORAGE_MAP.values().parallelStream()
|
||||
.forEach(viewableStorage -> viewableStorage.process(null));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user