joltup / react-native-threads

Create new JS processes for CPU intensive work
MIT License
755 stars 141 forks source link

Any guidance on using this library with version 0.70? #155

Open ThalesBMC opened 1 year ago

ThalesBMC commented 1 year ago

The library no longer functions with version 0.70 of react native. Any suggestions for resolving this issue or using an alternative library?

austinksmith commented 1 year ago

@ThalesBMC the problem is that facebook removed some of the java class files that were previously included in react native, the only way to fix this is a complete rewrite, Ive run into the same problem with my library which was a fork of this one, https://github.com/austinksmith/react-native-hamsters I managed to fix some of the issues with this react-native-threads library but supporting versions higher than 0.6.9 seems to be very difficult

devsticks commented 1 year ago

@austinksmith any updates perhaps? I'm working on a new app, so I have some flexibility with versioning and that, but I've really battled to find an up-to-date way to run processor-heavy async tasks away from the main thread (a TFLite model in my case). Would appreciate any help you can offer!

austinksmith commented 1 year ago

@devsticks I would recommend using my library Hamsters.js ( https://www.hamsters.io ) and using my react-native-hamsters package, as long as you use react native 0.69 or older it will work and you can follow my api and do some really cool stuff like put a function on its own thread or split a for loop across multiple threads just by changing 1 parameter. Eventually I'll try to tackle support for version 0.70 and newer but I took a look at the latest reactnative and they've completely removed ALL of the java files that this package and my package rely on so its going to take sometime to figure it all out. In the meantime you can use hamsters.js with react-native-hamsters and do parallel processing / multithreading without having to worry about things like thread communication and stuff.

oguimbal commented 11 months ago

Hi @austinksmith

We need something like react-native-threads or react-native-hamsters, but cant find anything that works on > 0.70 with Expo.

Did you, by any chance, had the time to look a bit into it?

We're willing to pledge a 2k$ bounty to solve this issue in the open-source ecosystem, if that helps.

That said, we're on tight schedule, and cant wait very long or else we'll have to do it ourselves (by "long", I mean that we'll start investigating around february). We just think it would be a shame to do that closed-source.

Would it be something that is interesting to you ? (or anyone reading this, for that matter)

austinksmith commented 11 months ago

@oguimbal While I'd love to help this is a big undertaking, facebook stripped out all the java files that these libraries both rely on. Without this java functionality we can't make it work, and recreating all the functionality of the old java files that used to be bundled with react native would be a major amount of work. I might be able to provide support for 0.70 but i couldn't do anything newer than that.

gaodeng commented 11 months ago

Hi @oguimbal,

I've come across the bounty offer for addressing the multi-threading issue in React Native >0.70 with Expo, and I'm interested in contributing to a solution. With the sponsorship you've proposed, I believe I can offer valuable assistance in this endeavor.

If you're still looking for support on this project, please feel free to reach out to me at gaodengming@gmail.com so we can discuss the details further.

gaodeng commented 11 months ago

Hi @austinksmith

We need something like react-native-threads or react-native-hamsters, but cant find anything that works on > 0.70 with Expo.

Did you, by any chance, had the time to look a bit into it?

We're willing to pledge a 2k$ bounty to solve this issue in the open-source ecosystem, if that helps.

That said, we're on tight schedule, and cant wait very long or else we'll have to do it ourselves (by "long", I mean that we'll start investigating around february). We just think it would be a shame to do that closed-source.

Would it be something that is interesting to you ? (or anyone reading this, for that matter)

Hi @oguimbal Just prepped the PR and a demo for testing! Check them out when you can. 😊

PR: https://github.com/joltup/react-native-threads/pull/156
Demo: https://github.com/gaodeng/react-native-threads-demo

athulantony95 commented 9 months ago

Hi @gaodeng i am using your forked library for a non-expo project. I ended up on this error when the new architecture is enabled. Whenever i comment the line in MainApplication.java

 packages.add(new RNThreadPackage(mReactNativeHost));

The error i mentioned in the github issue goes away. Can you help me or guide me to resolve the issue?

project info

npx react-native info
npm WARN ignoring workspace config at /Users/apple/xxx/xxxx/.npmrc
warn Package @sentry/react-native contains invalid configuration: "dependency.platforms.ios.sharedLibraries" is not allowed,"dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
info Fetching system and libraries information...
(node:9369) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
  OS: macOS 13.5
  CPU: (10) arm64 Apple M2 Pro
  Memory: 118.16 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: /opt/homebrew/opt/node@18/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.3
    path: /opt/homebrew/opt/node@18/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.21
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.10
    wanted: 0.72.10
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: Not found

npm notice
npm notice New minor version of npm available! 10.2.3 -> 10.4.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.4.0
npm notice Run npm install -g npm@10.4.0 to update!
npm notice

Error log

Exception in native call
                                                                                                    java.lang.RuntimeException: Could not invoke ThreadManager.startThread
                                                                                                        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
                                                                                                        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
                                                                                                        at com.facebook.jni.NativeRunnable.run(Native Method)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                        at android.os.Looper.loop(Looper.java:288)
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
                                                                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
                                                                                                        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188) 
                                                                                                        at com.facebook.jni.NativeRunnable.run(Native Method) 
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) 
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201) 
                                                                                                        at android.os.Looper.loop(Looper.java:288) 
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228) 
                                                                                                        at java.lang.Thread.run(Thread.java:1012) 
                                                                                                    Caused by: java.lang.AssertionError: TurboModules are enabled, but mTurboModuleRegistry hasn't been set.
                                                                                                        at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:19)
                                                                                                        at com.facebook.react.bridge.CatalystInstanceImpl.getTurboModuleRegistry(CatalystInstanceImpl.java:474)
                                                                                                        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:485)
                                                                                                        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:469)
                                                                                                        at com.facebook.react.bridge.ReactContext.getNativeModule(ReactContext.java:205)
                                                                                                        at com.reactlibrary.JSThread.runFromContext(JSThread.java:34)
                                                                                                        at com.reactlibrary.RNThreadModule.startThread(RNThreadModule.java:82)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) 
                                                                                                        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188) 
                                                                                                        at com.facebook.jni.NativeRunnable.run(Native Method) 
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) 
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201) 
                                                                                                        at android.os.Looper.loop(Looper.java:288) 
                                                                                                    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)                                                                                                    at java.lang.Thread.run(Thread.java:1012) 
austinksmith commented 8 months ago

Hi @austinksmith We need something like react-native-threads or react-native-hamsters, but cant find anything that works on > 0.70 with Expo. Did you, by any chance, had the time to look a bit into it? We're willing to pledge a 2k$ bounty to solve this issue in the open-source ecosystem, if that helps. That said, we're on tight schedule, and cant wait very long or else we'll have to do it ourselves (by "long", I mean that we'll start investigating around february). We just think it would be a shame to do that closed-source. Would it be something that is interesting to you ? (or anyone reading this, for that matter)

Hi @oguimbal Just prepped the PR and a demo for testing! Check them out when you can. 😊

PR: #156 Demo: https://github.com/gaodeng/react-native-threads-demo

Is this for expo only? It doesn't seem to patch support for the old java packages for react-native. When I took a look at this support for 0.70 was required recreating some logging package that was removed.