-
-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android-java target batching is very slow #1051
Comments
Sorry but putting a large array on the stack makes no sense, at best it does not result in a difference, at worst - stack overflow. Allocating things from the stack is faster than from the heap but there's no speed difference in using things from the stack or the heap. |
Okay, so the problem is with putting floats in |
I checked JNI approach with direct bytebuffer and Spoiler with silly things#include "test.h"
#include <stdlib.h>
#include <string.h>
JNIEXPORT
void JNICALL Java_jni_Test_copy(JNIEnv *env, jclass clazz, jobject dst, jfloatArray src, jint offset, jint len) {
unsigned char* pDst = (unsigned char*)(*env)->GetDirectBufferAddress(env, dst);
float* pSrc = (float*)(*env)->GetPrimitiveArrayCritical(env, src, 0);
memcpy(pDst, pSrc + offset, len * 4);
(*env)->ReleasePrimitiveArrayCritical(env, src, pSrc, 0);
}
JNIEXPORT
void JNICALL Java_jni_Test_set(JNIEnv *env, jclass clazz, jobject dst, jint index, jfloat value) {
unsigned char* pDst = (unsigned char*)(*env)->GetDirectBufferAddress(env, dst);
memcpy(pDst + index, &value, 4);
}
JNIEXPORT
jfloat JNICALL Java_jni_Test_get(JNIEnv *env, jclass clazz, jobject dst, jint index) {
int *iBuf = (*env)->GetDirectBufferAddress(env, dst);
float value;
memcpy(&value, iBuf + index, 4);
return value;
} package jni;
@:classCode('
static {
System.loadLibrary("kore");
}
')
class Test {
@:native public static function copy(
to: java.nio.ByteBuffer, from: java.NativeArray<Single>,
offset: Int, size: Int
): Void;
@:native public static function get(to: java.nio.FloatBuffer, i: Int): Single;
@:native public static function set(to: java.nio.FloatBuffer, i: Int, value: Single): Void;
} build.gradle requres only two |
Looks like this is a won't-fix. |
Because of vertex array pushing every frame. I try to optimize
Float32Array
implementation in #1041 replacingFloatBuffer
toNativeArray<Single>
, but it is still bad, so there is two ways:sun.misc.Unsafe
with reflection to put floats in FloatBuffer (LWJGL main way)Also, maybe haxe jvm supports jvm-pasting and we can do something on jvm for that.
Some articles:
https://github.com/LWJGL/lwjgl3-wiki/wiki/1.3.-Memory-FAQ
https://www.badlogicgames.com/wordpress/?p=904
Not sure if
Unsafe
class available on all androids (with reflection), but it's still requres some code extraction from LWJGL/MemoryStack.java and MemoryUtil.java.JNI should be easier to implement (if it has way to push floats in FloatBuffer), but it's requres some c/cpp compiler integration. Also not sure about Java native method call overhead.
The text was updated successfully, but these errors were encountered: