Skip to content

Move JS Processing to background thread or allow creation of other WebWorkers/Threads #85

Closed

Description

@NathanaelA

From what I understand everything runs on the primary thread. So this is a feature request -- but if done possible sooner would eliminate any later incompatibilities. Having the main thread run the interface and JS runtimes means that hiccups can and will occur frequently. Either the design where the interface is run on its own thread; and the engine is on its own or the ability to start webworks will eliminate these types of issues where you need to do any long running calculations.

Please vote for this feature in our ideas portal.

Activity

  1. RangerMauve commented on Apr 27, 2015

    @RangerMauve

    Yeah, I'm pretty sure ReactNative does something along those lines at the moment. Even if JS is in its own thread, I still think that having something like a WebWorker would be very useful feature to have.

  2. emmanuelbuah commented on May 6, 2015

    @emmanuelbuah

    +1 I made a comment about this on the Q&A blog post and didn't get a respond. I think this is important to, especially when animation or long background task comes into play. I hope other upvotes this feature. It very important for performance.

  3. wan54 commented on May 19, 2015

    @wan54

    +1

  4. ligaz commented on May 21, 2015

    @ligaz
    Contributor

    My reply was originally posted on the forums but I'm reposting it here is well:

    This is really a tough engineering problem to solve as there is no silver bullet here. For example we can introduce WebWorkers but they do have their flaws as well. There is this new re-thinking of WebWorkers in the web space - SharedWorker that tries to solve some of the limitations there. There are other concept like immutable data structures that are slowly gaining momentum.

    I also want to mention that React Native solution has its own flaws. Being always on a separate thread means that you will constantly have to marshall data (in their case serializing/deserializing JSON) between the JS thread and the UI thread. This might be beneficial for compute intensive JavaScript but in the general case the price you pay is significantly higher compared to doing it in the UI thread.

    In order for us to provide the right solution we need your use cases. What is your particular scenario that you need to perform compute intensive JavaScript operations? Having more use cases on the table will help us drive this forward.

  5. RangerMauve commented on May 21, 2015

    @RangerMauve

    Persoanlly, more I'm a fan of the code running in the UI thread by default. I just think that having the option to run things in a worker would be a useful feature to have for projects that would need a separate thread for heavy computations and what not. But even more so, it'd be nice if we had an abstraction that would let us write something like and Android Service which would let our JS code run even when it's not part of the UI of an app.

  6. ndarilek commented on May 21, 2015

    @ndarilek
  7. RangerMauve commented on May 21, 2015

    @RangerMauve

    +1 to what @ndarilek is saying. I think that ServiceWorker is a better abstraction than WebWorkers for this case, though. Since WebWorkers are more like a separate thread and must be started by the UI, where as a ServiceWorker can run even when a website isn't even opened.

  8. ndarilek commented on May 21, 2015

    @ndarilek
  9. NathanaelA commented on May 21, 2015

    @NathanaelA
    Author
  10. VinceOPS commented on Jun 10, 2015

    @VinceOPS

    Hi everyone,

    I looked at the documentation (perhaps I did it wrong) and saw nothing about multi-threading too. This thread is actually quite new so I was simply wondering the status of this request?

    Thanks a lot. Can't wait to see all NativeScript possibilities.

    Regards.

  11. valentinstoychev commented on Jun 11, 2015

    @valentinstoychev

    Hi @VinceOPS, this issues is still not in active development. We treat it with high priority and we are evaluating what will be the best strategy here based on all the feedback.

    Can you please share your scenario that requires multithreading.

    Thanks!

  12. VinceOPS commented on Jun 11, 2015

    @VinceOPS

    Hi @valentinstoychev. Understood!

    The typical scenario would be any common background task like fetching some data from a webservice (which could eventually timeout) or a database. Inserting group of rows in a database, too. Generating a .CSV file (sent, later, by email) with few hundred or thousands or entries...

    I hope it helps.

    Thanks!

    Regards.

  13. valentinstoychev commented on Jun 11, 2015

    @valentinstoychev

    Thanks @VinceOPS - this helps a lot!

  14. NekR commented on Jul 23, 2015

    @NekR

    @ligaz

    This might be beneficial for compute intensive JavaScript but in the general case the price you pay is significantly higher compared to doing it in the UI thread.

    Thing here is that React's JS computations is heavy, this is why they went native and on separate thread by default. Here, for {N} is not real need to be by default on separate thread, but having ability to run system thread with JS handling would be good since without it smooth UI is hard thing (see how hard it's for mobile web to live on one thread).

  15. cime commented on Aug 26, 2015

    @cime

    Anything new on this one?
    Image/Bitmap processing is one more thing that could be done in background.

  16. 70 remaining items

  17. sitefinitysteve commented on Mar 24, 2016

    @sitefinitysteve
    Contributor

    Personally I would just like a way to "process" something off somewhere else and whatever is handing that be a core part of {N} so I know it's fully tested and rock-solid. I'd be less optimistic about this being done generically by a plugin author who might disappear in 2 months.

  18. x4080 commented on Mar 24, 2016

    @x4080

    Yes and plugins is too big for small services that needs async like async .. Task :)

  19. NathanaelA commented on Mar 24, 2016

    @NathanaelA
    Author
  20. paandahl commented on Mar 25, 2016

    @paandahl

    One scenario for me would be doing data transformations, i.e. iterating on datasets fetched from my backend. A workaround is to do the transformations server-side, but it seems a bit counter intuitive, as the transformations will often be specific to a given view.

    A concrete example where background processing made a huge difference in my native code: I am displaying a map, and fetching points of interests inside the area currently displayed. After the POIs are fetched, I need to calculate the display location for each of them, and group them if they are too close to each other. Doing this on the UI thread, will make the map unresponsive and sluggish.

  21. NathanaelA commented on Mar 25, 2016

    @NathanaelA
    Author
  22. Stavanger75 commented on Apr 3, 2016

    @Stavanger75

    +1
    I hope it will be possible to send the reference and not the object between the threads. (for performance)

  23. x4080 commented on Apr 11, 2016

    @x4080

    Any plans for blog to develop native plugin for background threading using Android studio and xcode ? Or maybe NS guys can describe how they develop the tns plugin? It will be great time saving

    Thanks

  24. valentinstoychev commented on May 11, 2016

    @valentinstoychev

    Hey everyone - In order to explain better the current state of the threading model we wrote a blog post. It also outlines what we are planning for the future and how you can use background threads now.

    http://developer.telerik.com/featured/benefits-single-threading-model-nativescript/

  25. x4080 commented on May 11, 2016

    @x4080

    nice blog, so the next JavaScript background thread will be able to pass variable from the main JavaScript? and in iOS will it use wkwebview for more performance?

  26. manojdcoder commented on Jul 18, 2016

    @manojdcoder

    +1

  27. valentinstoychev commented on Aug 11, 2016

    @valentinstoychev

    I'm closing this issue, lets use the other ones for the current state -
    NativeScript/ios-jsc#620
    NativeScript/android#532

    We would love to continue the discussion there on the current thinking!

  28. added a commit that references this issue on Mar 20, 2019
  29. lock commented on Aug 29, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  30. locked and limited conversation to collaborators on Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions