Skip to content

Latest commit

 

History

History
77 lines (50 loc) · 2.56 KB

DEVELOPMENT.md

File metadata and controls

77 lines (50 loc) · 2.56 KB

Installation

Before PR merge, you should use this installation step.

# Install from source
 npm i 'mybigday/transformers.js#merge'

# or prerelease maintained by BRICKS
npm i @fugood/transformers

Basic Polyfills & Fixes

import 'text-encoding-polyfill'; // support TextEncoder
import { Buffer } from 'buffer';
import XRegExp from 'xregexp';
global.Buffer = Buffer;
// replace default RegExp to support unicode
const nativeRegExp = global.RegExp;
const newRegExp = (...args) => {
global.RegExp = nativeRegExp;
const result = XRegExp(...args);
global.RegExp = newRegExp;
return result;
};
global.RegExp = newRegExp;

'@babel/plugin-proposal-export-namespace-from',

Android

  • Add largeHeap to android/app/src/main/AndroidManifest.xml
<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:theme="@style/AppTheme"
+  android:largeHeap="true">

Onnxruntime

Version

Should ensure onnxruntime-common and onnxruntime-react-native version are same. You could using resolution (yarn) or overrides (npm) to force them.

For example.

"resolutions": {
"jpeg-js": "^0.4.4",
"node-fetch": "^2.6.7",
"xml2js": "^0.5.0",
"onnxruntime-common": "1.17.0",
"onnxruntime-react-native": "1.17.0"
}

ONNX Runtime patch work for LM models

If you use onnxruntime-react-native<1.17.0, you should patch the library.

Performance Improvement

Image Process

Way 1: GCanvas

https://github.com/hans00/react-native-transformers-example/tree/gcanvas

May make app unstable. Should more reuse canvas instance

  • @flyskywhy/react-native-browser-polyfill
  • @flyskywhy/react-native-gcanvas

Known Issue

  • The offscreen canvas too small will not get full decoded image data.
  • The canvas too large will crash.
  • Create too many canvas may cause crash (include refresh app).

Way 2: Skia

Stable, but slightly slower than gcanvas

import 'react-native-skia-offscreencanvas/polyfill';