Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21520

Support threaded JavaScript imports

    XMLWordPrintable

Details

    Description

      Task Description:

      The current WorkerScript feature has several shortcomings. It would be preferable if we were to support a ".pragma threaded" syntax which allowed functions of an imported JavaScript file which specified that pragma to be run in a separate thread. We should ensure that JavaScript files from remote locations can be imported in this manner.

      Implementation Stages:

      1) port previous research to v8
      2) write unit tests to ensure that work is performed in the worker thread as required
      3) write unit tests to ensure that a client callback can be provided to the threaded js functions
      4) write unit tests to ensure that remote scripts can be loaded in this fashion
      5) write documentation for the feature

      Benchmarking of the completed feature may show that some improvements may be required during argument serialisation in order for threaded scripts to be performant, but that is currently out of scope for this task.

      Expected Outcomes:

      1) It is expected that the client will be able to define a script like:

      .pragma threaded
      
      function longFunc(inputs) {
          // ... process inputs
      }
      

      which may be imported from another QML or JavaScript file. Calling the longFunc() should result in the time-consuming processing to be performed without blocking the main thread.

      2) Furthermore, clients should be able to pass in a callback function as an argument to the threaded JS functions:

      .pragma threaded
      
      function longFunc(inputs) {
          var result;
          // ... process inputs
          return result;
      }
      
      function doWork(inputs, callback) {
          var result = longFunc(inputs);
          callback(result);
      }
      

      in order to be able to receive results from the threaded JS functions once processing is complete.

      3) .pragma threaded scripts should be able to be imported from remote URLs, thereby maintaining the network-transparency language feature of QML.

      -----------------------

      Current status (26/09/2011)

      Porting of original code (from Bea) completed, and basic unit tests complete. Documentation started but not complete. Currently investigating recallbacks (passing function objects from worker thread back to main thread, and converting them to original script object function proxy form).

      Serialisation improvements and imports within .pragma threaded scripts are still out of scope, although some benchmarking of different serialisation methods will be performed.

      -----------------------

      Current status (28/09/2011)

      Benchmarking of two serialisation methods (JSON.parse/stringify and QV8Worker::Serialize/Deserialize) was performed. It showed that JSON serialisation of JS Objects was significantly faster, while serialisation of simple types was slower than via QV8Worker in the typical case. I've added support for both types of serialisation to the .pragma threaded implementation, selectable via ifdef (as it may be that we should optimise QV8Worker rather than simply use JSON, depending on further research).

      Recallbacks (and recursive calls between main and worker thread) has also been implemented, and unit tests for the functionality added.

      Remaining tasks:

      • Documentation
      • Code review

      -----------------------

      Current status (30/09/2011)

      Documentation from the original implementation (from Bea) has been added and expanded to include the new functionality. Code review has not yet been done, as the unit tests were expanded and showed problems which need resolving prior to final code review.

      The problems include deficiencies in the implementation wrt anonymous functions and cross-script function arguments. These problems have mostly been resolved, however some v8 handles are being disposed incorrectly.

      Remaining tasks

      • debugging the handle management
      • code review

      -----------------------

      Current Status (05/10/2011)

      All handle management bugs were solved, implementation supports passing argument functions both directions transparently (incl. anonymous functions). Code review is in progress.

      Currently, list model arguments are only partially supported (you can pass them from the main thread to the worker thread, and the worker thread can populate the listmodel; but you cannot pass them from the worker thread to the main thread or to other worker threads). As with QV8Worker::serialize/deserialize performance improvements, improving the QV8Worker's support for ListModel arguments is out of scope of this task.

      IE: this task is done, pending review outcomes.

      -------------------------

      Current Status (11/10/2011)

      Code was reviewed yesterday, outcome was that the current solution suffers from a circular reference problem in certain circumstances. Decision was made to simplify the solution to not allow passing of function arguments from the worker thread back to the main thread, to avoid this problem (at least initially). This limitation means that the current implementation is over-engineered for the new scope, and so should be changed to a much simpler implementation.

      As such, I need to rewrite the solution, and get it re-reviewed.

      Attachments

        For Gerrit Dashboard: QTBUG-21520
        # Subject Branch Project Status CR V

        Activity

          People

            shausman Simon Hausmann
            chriadam Christopher Adams (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 2 weeks Original Estimate - 2 weeks
                2w
                Remaining:
                Time Spent - 2 weeks, 2 days Remaining Estimate - 2 days
                2d
                Logged:
                Time Spent - 2 weeks, 2 days Remaining Estimate - 2 days
                2w 2d

                Gerrit Reviews

                  There are no open Gerrit changes