Skip to content

Commit

Permalink
perf: Add @FastNative flags to critical Frame Processor methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Mar 26, 2024
1 parent 4c00ffd commit ff2005b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;

import dalvik.annotation.optimization.FastNative;

/**
* Represents a JS Frame Processor
* @noinspection JavaJniMissingFunction
Expand All @@ -15,6 +17,7 @@ public final class FrameProcessor {
/**
* Call the JS Frame Processor function with the given Frame
*/
@FastNative
public native void call(Frame frame);

/** @noinspection FieldCanBeLocal, unused */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.nio.ByteBuffer;

import dalvik.annotation.optimization.FastNative;

/**
* A JSI TypedArray/ArrayBuffer implementation used for passing buffers between JS and Native without copying data.
* ByteBuffers are used for efficient data transfer.
Expand Down Expand Up @@ -47,13 +49,17 @@ public SharedArray(VisionCameraProxy proxy, ByteBuffer byteBuffer) {
/**
* Gets the direct ByteBuffer that can be used to directly update the JSI ArrayBuffer.
*/
@FastNative
public native ByteBuffer getByteBuffer();

/**
* Gets the size of the ByteBuffer.
*/
@FastNative
public native int getSize();

@FastNative
private native HybridData initHybrid(VisionCameraProxy proxy, int size);
@FastNative
private native HybridData initHybrid(VisionCameraProxy proxy, ByteBuffer byteBuffer);
}

2 comments on commit ff2005b

@mschmid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I get build errors when upgrading past this change:

/mobile-app/node_modules/react-native-vision-camera/android/src/main/java/com/mrousavy/camera/frameprocessor/SharedArray.java:63: error: cannot find symbol
    @FastNative
     ^
  symbol:   class FastNative
  location: class SharedArray

It seems my build needs some extra setup for this or I am on a lower Android SDK than necessary.

Currently I use

        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        kotlinVersion = "1.8.20"

Do you have any hints @mrousavy?

@mrousavy
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does work for me. Are you sure you added the import at the top?

Please # to comment.