d-markey / squadron

Multithreading and worker thread pool for Dart / Flutter, to offload CPU-bound and heavy I/O tasks to Isolate or Web Worker threads.
https://pub.dev/packages/squadron
MIT License
79 stars 0 forks source link

No documentation for release mode #6

Closed SaadArdati closed 2 years ago

SaadArdati commented 2 years ago

When building using flutter build web, the app always throws an error that it couldn't locate the worker.dart.js we created.

I had to add this script in my index.html to get it to load.

  <!-- Load our solver_worker.dart.js file-->
  <script>
    const scriptTag = document.createElement('script');
    scriptTag.src = 'solver_worker.dart.js';
    scriptTag.defer = true;
    scriptTag.type = 'text/javascript';
    document.body.append(scriptTag);
  </script>
d-markey commented 2 years ago

Indeed, thanks for the feedback I'll look into this issue.

d-markey commented 2 years ago

Hello, I haven't looked at this issue yet but updated the documentation with your insights.

I hope you're getting the results you wanted from Squadron ;-)

SaadArdati commented 2 years ago

We are! It's been amazing! We did hit a huge issue where we can't reference flutter to calculate text width and height using textPainter... If you know a way around this, do tell!

We had to disable the thread and run it on the main thread instead to get it to work :(

d-markey commented 2 years ago

Indeed, secondary threads are restricted in what they can do and UI stuff can only be done in the main thread. I'll think about something and will let you know. That will involve communication between your worker and the main thread, so that means adding some ovehead but it might be worth it.

SaadArdati commented 2 years ago

One workaround is precalculating all possible sizes for a given Text, but the initial overhead was less than ideal.

d-markey commented 2 years ago

That's a possibility, but I have a POC and can confirm there's a way with workers. It needs a bit of polish so I'll post some update this weekend. Text sizes will have to be calculated from the main Flutter thread anyway. You'll have to try and see if the overhead due to thread messaging is worth it.

d-markey commented 2 years ago

Squadron 3.3 published and https://github.com/d-markey/squadron_sample updated with a sample for computing text size. The sample is basic and results will be visible in the browser's JavaScript console.

SaadArdati commented 2 years ago

Squadron 3.3 published and https://github.com/d-markey/squadron_sample updated with a sample for computing text size. The sample is basic and results will be visible in the browser's JavaScript console.

You can straight up reference Flutter classes??? How is the dart js command okay with this? TextPainter relies on dart:ui which crashes when used with dart js. It's the whole reason we pulled any dart:ui references from our impl. How is this working fine??

SaadArdati commented 2 years ago

Reading your changes and.. WAW. I'm going to try this out and report back to you <3 This is craazyyyy