Skip to content

Commit 1f9151c

Browse files
authored
Merge pull request #1 from MachineMC/1.1
1.1
2 parents 23dfce8 + 36754f5 commit 1f9151c

107 files changed

Lines changed: 3545 additions & 1571 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 143 additions & 40 deletions
Large diffs are not rendered by default.

build-logic/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ tasks {
1212
jvmTarget = "21"
1313
}
1414
}
15-
}
15+
}

build-logic/src/main/kotlin/java-library-convention.gradle.kts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ val libs = project.rootProject
1414
.getByType(VersionCatalogsExtension::class)
1515
.named("libs")
1616

17+
//
18+
// Repositories and Dependencies
19+
//
20+
1721
repositories {
1822
mavenCentral()
1923
}
@@ -26,37 +30,24 @@ dependencies {
2630
testImplementation(libs.findLibrary("junit-params").get())
2731
}
2832

33+
//
34+
// Java configuration
35+
//
36+
2937
java {
3038
sourceCompatibility = JavaVersion.VERSION_21
3139
targetCompatibility = JavaVersion.VERSION_21
3240
withSourcesJar()
3341
}
3442

35-
tasks.withType<JavaCompile>().configureEach {
36-
options.compilerArgs.add("--enable-preview")
37-
}
38-
tasks.withType<Test>().configureEach {
39-
jvmArgs("--enable-preview")
40-
}
41-
tasks.withType<JavaExec>().configureEach {
42-
jvmArgs("--enable-preview")
43-
}
43+
//
44+
// Task configurations
45+
//
4446

4547
tasks {
46-
compileJava {
48+
withType<JavaCompile> {
4749
options.release.set(21)
4850
options.encoding = Charsets.UTF_8.name()
49-
// options.compilerArgs.addAll(listOf(
50-
// "-Xlint:preview",
51-
// "-Xlint:unchecked",
52-
// "-Xlint:deprecation"
53-
// ))
54-
}
55-
javadoc {
56-
options.encoding = Charsets.UTF_8.name()
57-
}
58-
processResources {
59-
filteringCharset = Charsets.UTF_8.name()
6051
}
6152
test {
6253
useJUnitPlatform()

gradle.properties

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Group and version
22
group = org.machinemc.paklet
3-
version = 1.0.1
3+
version = 1.1
44

55
# Dependency versions
66
jetbrainsAnnotations = 24.1.0
77
junit = 5.10.1
88
asm = 9.6
99
netty = 4.1.80.Final
1010
googleAutoservice = 1.1.1
11-
googleGson = 2.10.1
11+
googleGson = 2.10.1
12+
jmh = 1.37
13+
14+
# Plugins
15+
champeauJmh = 0.7.2

jmh-benchmarks/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id("java-library-convention")
3+
id("org.machinemc.paklet-plugin")
4+
alias(libs.plugins.champeau.jmh)
5+
}
6+
7+
dependencies {
8+
implementation(libs.netty)
9+
10+
jmhAnnotationProcessor(project(":paklet-processor"))
11+
12+
implementation(project(":paklet-api"))
13+
implementation(project(":paklet-core"))
14+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.machinemc.paklet;
2+
3+
import org.machinemc.paklet.packets.ArrayPacket;
4+
import org.machinemc.paklet.packets.CollectionPacket;
5+
import org.machinemc.paklet.packets.SimplePacket;
6+
7+
import java.util.List;
8+
9+
public final class BenchmarkPackets {
10+
11+
private BenchmarkPackets() {
12+
throw new UnsupportedOperationException();
13+
}
14+
15+
public static SimplePacket simplePacket() {
16+
var packet = new SimplePacket();
17+
packet.f1 = 20;
18+
packet.f2 = true;
19+
packet.f3 = 10;
20+
packet.f4 = "Hello World!";
21+
packet.f5 = 1.5f;
22+
return packet;
23+
}
24+
25+
public static ArrayPacket arrayPacket() {
26+
var packet = new ArrayPacket();
27+
packet.intArray = new int[] { 1, 2, 3, 4, 5, 6 };
28+
packet.nestedStringArray = new String[][] { new String[] { "Hello World" }, new String[0] };
29+
packet.doubleArray = new double[] { 1, 2, 3, 4, 5, 6, 7, 8 };
30+
return packet;
31+
}
32+
33+
public static CollectionPacket collectionPacket() {
34+
var packet = new CollectionPacket();
35+
packet.stringList = List.of("Hello", "World", "!", "Foo", "Bar");
36+
packet.integerCollection = List.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
37+
packet.nestedStringList = List.of(packet.stringList, packet.stringList);
38+
return packet;
39+
}
40+
41+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.machinemc.paklet;
2+
3+
import io.netty.buffer.Unpooled;
4+
import org.machinemc.paklet.netty.NettyDataVisitor;
5+
import org.machinemc.paklet.packets.ArrayPacket;
6+
import org.machinemc.paklet.packets.CollectionPacket;
7+
import org.machinemc.paklet.packets.SimplePacket;
8+
import org.machinemc.paklet.serialization.SerializerProvider;
9+
import org.machinemc.paklet.serialization.catalogue.DefaultSerializationRules;
10+
import org.machinemc.paklet.serialization.catalogue.DefaultSerializers;
11+
import org.openjdk.jmh.annotations.*;
12+
13+
import java.util.concurrent.TimeUnit;
14+
15+
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS)
16+
@Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
17+
@BenchmarkMode(Mode.AverageTime)
18+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
19+
@State(Scope.Benchmark)
20+
public class PacketReadBenchmark {
21+
22+
PacketFactory factory;
23+
24+
@Setup
25+
public void setup() {
26+
SerializerProvider serializerProvider = new SerializerProviderImpl();
27+
serializerProvider.addSerializers(DefaultSerializers.class);
28+
serializerProvider.addSerializationRules(DefaultSerializationRules.class);
29+
30+
factory = new PacketFactoryImpl(PacketEncoder.varInt(), serializerProvider);
31+
factory.addPackets(BenchmarkPackets.class);
32+
}
33+
34+
@Benchmark
35+
public void simplePacketRead100() {
36+
SimplePacket packet = BenchmarkPackets.simplePacket();
37+
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer());
38+
factory.write(packet, visitor);
39+
for (int i = 0; i < 100; i++) {
40+
factory.create(Packet.DEFAULT, visitor);
41+
visitor.readerIndex(0);
42+
}
43+
}
44+
45+
@Benchmark
46+
public void arrayPacketRead100() {
47+
ArrayPacket packet = BenchmarkPackets.arrayPacket();
48+
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer());
49+
factory.write(packet, visitor);
50+
for (int i = 0; i < 100; i++) {
51+
factory.create(Packet.DEFAULT, visitor);
52+
visitor.readerIndex(0);
53+
}
54+
}
55+
56+
@Benchmark
57+
public void collectionPacketRead100() {
58+
CollectionPacket packet = BenchmarkPackets.collectionPacket();
59+
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer());
60+
factory.write(packet, visitor);
61+
for (int i = 0; i < 100; i++) {
62+
factory.create(Packet.DEFAULT, visitor);
63+
visitor.readerIndex(0);
64+
}
65+
}
66+
67+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.machinemc.paklet;
2+
3+
import io.netty.buffer.Unpooled;
4+
import org.machinemc.paklet.netty.NettyDataVisitor;
5+
import org.machinemc.paklet.packets.ArrayPacket;
6+
import org.machinemc.paklet.packets.CollectionPacket;
7+
import org.machinemc.paklet.packets.SimplePacket;
8+
import org.machinemc.paklet.serialization.SerializerProvider;
9+
import org.machinemc.paklet.serialization.catalogue.DefaultSerializationRules;
10+
import org.machinemc.paklet.serialization.catalogue.DefaultSerializers;
11+
import org.openjdk.jmh.annotations.*;
12+
13+
import java.util.concurrent.TimeUnit;
14+
15+
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS)
16+
@Measurement(iterations = 5, time = 500, timeUnit = TimeUnit.MILLISECONDS)
17+
@BenchmarkMode(Mode.AverageTime)
18+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
19+
@State(Scope.Benchmark)
20+
public class PacketWriteBenchmark {
21+
22+
PacketFactory factory;
23+
24+
@Setup
25+
public void setup() {
26+
SerializerProvider serializerProvider = new SerializerProviderImpl();
27+
serializerProvider.addSerializers(DefaultSerializers.class);
28+
serializerProvider.addSerializationRules(DefaultSerializationRules.class);
29+
30+
factory = new PacketFactoryImpl(PacketEncoder.varInt(), serializerProvider);
31+
factory.addPackets(BenchmarkPackets.class);
32+
}
33+
34+
@Benchmark
35+
public void simplePacketWrite100() {
36+
SimplePacket packet = BenchmarkPackets.simplePacket();
37+
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer());
38+
for (int i = 0; i < 100; i++) {
39+
factory.write(packet, visitor);
40+
visitor.writerIndex(0);
41+
}
42+
}
43+
44+
@Benchmark
45+
public void arrayPacketWrite100() {
46+
ArrayPacket packet = BenchmarkPackets.arrayPacket();
47+
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer());
48+
for (int i = 0; i < 100; i++) {
49+
factory.write(packet, visitor);
50+
visitor.writerIndex(0);
51+
}
52+
}
53+
54+
@Benchmark
55+
public void collectionPacketWrite100() {
56+
CollectionPacket packet = BenchmarkPackets.collectionPacket();
57+
DataVisitor visitor = new NettyDataVisitor(Unpooled.buffer());
58+
for (int i = 0; i < 100; i++) {
59+
factory.write(packet, visitor);
60+
visitor.writerIndex(0);
61+
}
62+
}
63+
64+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.machinemc.paklet.packets;
2+
3+
import org.machinemc.paklet.BenchmarkPackets;
4+
import org.machinemc.paklet.Packet;
5+
6+
@Packet(id = 1, catalogue = BenchmarkPackets.class)
7+
public class ArrayPacket {
8+
9+
public int[] intArray;
10+
public String[][] nestedStringArray;
11+
public double[] doubleArray;
12+
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.machinemc.paklet.packets;
2+
3+
import org.machinemc.paklet.BenchmarkPackets;
4+
import org.machinemc.paklet.Packet;
5+
6+
import java.util.Collection;
7+
import java.util.List;
8+
9+
@Packet(id = 3, catalogue = BenchmarkPackets.class)
10+
public class CollectionPacket {
11+
12+
public List<String> stringList;
13+
public Collection<Integer> integerCollection;
14+
public List<List<String>> nestedStringList;
15+
16+
}

0 commit comments

Comments
 (0)