13
0
geforkt von Mirrors/Velocity

Switch to zlib-ng

zlib-ng boasts higher throughput than regular zlib, by combining patches
from Cloudflare, zlib, and ARM's improvements to zlib along with a more
modern codebase.

Profiling consistently shows that compression is the largest CPU expense
by far, so even a minor speed-up here is significant.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-09-08 23:30:28 -04:00
Ursprung 63dcc56735
Commit e21c33d435
8 geänderte Dateien mit 34 neuen und 8 gelöschten Zeilen

4
.gitignore vendored
Datei anzeigen

@ -85,3 +85,7 @@ server-icon.png
/bin/ /bin/
run/ run/
plugins/ plugins/
### Natives stuff ###
natives/mbedtls
natives/zlib-ng

Datei anzeigen

@ -1,10 +1,21 @@
#!/bin/bash #!/bin/bash
if [ ! -d zlib-ng ]; then
echo "Cloning zlib-ng..."
git clone https://github.com/zlib-ng/zlib-ng.git
fi
echo "Compiling zlib-ng..."
cd zlib-ng
CFLAGS="-fPIC -O3" ./configure --zlib-compat --static
make clean && make
cd ..
# Modify as you need. # Modify as you need.
MBEDTLS_ROOT=mbedtls MBEDTLS_ROOT=mbedtls
CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/ -fPIC -shared" CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/ -fPIC -shared"
gcc $CFLAGS -lz src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ gcc $CFLAGS -Izlib-ng src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \
src/main/c/jni_zlib_common.c -o src/main/resources/linux_x64/velocity-compress.so src/main/c/jni_zlib_common.c zlib-ng/libz.a -o src/main/resources/linux_x64/velocity-compress.so
gcc $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \ gcc $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \
$MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \ $MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \
-o src/main/resources/linux_x64/velocity-cipher.so -o src/main/resources/linux_x64/velocity-cipher.so

Datei anzeigen

@ -1,12 +1,23 @@
#!/bin/bash #!/bin/bash
if [ ! -d zlib-ng ]; then
echo "Cloning zlib-ng..."
git clone https://github.com/zlib-ng/zlib-ng.git
fi
echo "Compiling zlib-ng..."
cd zlib-ng
CFLAGS="-fPIC -O3" ./configure --zlib-compat --static
make clean && make
cd ..
# Modify as you need. # Modify as you need.
MBEDTLS_ROOT=mbedtls MBEDTLS_ROOT=mbedtls
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin/ -fPIC -shared" CFLAGS="-O3 -I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin/ -fPIC -shared"
clang $CFLAGS -lz src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \ clang $CFLAGS -Izlib-ng src/main/c/jni_util.c src/main/c/jni_zlib_deflate.c src/main/c/jni_zlib_inflate.c \
src/main/c/jni_zlib_common.c -o src/main/resources/macosx/velocity-compress.dylib src/main/c/jni_zlib_common.c zlib-ng/libz.a -o src/main/resources/macosx/velocity-compress.dylib
clang $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \ clang $CFLAGS -I $MBEDTLS_ROOT/include -shared $MBEDTLS_ROOT/library/aes.c $MBEDTLS_ROOT/library/aesni.c \
$MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \ $MBEDTLS_ROOT/library/platform.c $MBEDTLS_ROOT/library/platform_util.c src/main/c/jni_util.c src/main/c/jni_cipher.c \
-o src/main/resources/macosx/velocity-cipher.dylib -o src/main/resources/macosx/velocity-cipher.dylib

Datei anzeigen

@ -8,7 +8,7 @@ void JNICALL
check_zlib_free(JNIEnv *env, z_stream *stream, bool deflate) check_zlib_free(JNIEnv *env, z_stream *stream, bool deflate)
{ {
int ret = deflate ? deflateEnd(stream) : inflateEnd(stream); int ret = deflate ? deflateEnd(stream) : inflateEnd(stream);
char *msg = stream->msg; const char *msg = stream->msg;
free((void*) stream); free((void*) stream);
switch (ret) { switch (ret) {

Datei anzeigen

@ -33,7 +33,7 @@ Java_com_velocitypowered_natives_compression_NativeZlibDeflate_init(JNIEnv *env,
if (ret == Z_OK) { if (ret == Z_OK) {
return (jlong) stream; return (jlong) stream;
} else { } else {
char *zlib_msg = stream->msg; const char *zlib_msg = stream->msg;
free(stream); free(stream);
switch (ret) { switch (ret) {
case Z_MEM_ERROR: case Z_MEM_ERROR:

Datei anzeigen

@ -32,7 +32,7 @@ Java_com_velocitypowered_natives_compression_NativeZlibInflate_init(JNIEnv *env,
if (ret == Z_OK) { if (ret == Z_OK) {
return (jlong) stream; return (jlong) stream;
} else { } else {
char *zlib_msg = stream->msg; const char *zlib_msg = stream->msg;
free(stream); free(stream);
switch (ret) { switch (ret) {
case Z_MEM_ERROR: case Z_MEM_ERROR: