big-r81 commented on code in PR #4627:
URL: https://github.com/apache/couchdb/pull/4627#discussion_r1590933133


##########
configure.ps1:
##########
@@ -145,6 +150,17 @@ $WithClouseau = $(If ($EnableClouseau) {1} else {0})
 $Hostname = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName
 $WithProper = (-not $DisableProper).ToString().ToLower()
 $ErlangMD5 = ($EnableErlangMD5).ToString().ToLower()
+$WithSpiderMonkey = (-not $DisableSpiderMonkey).ToString().ToLower()
+
+if ($JSEngine -eq "quickjs") {
+    $WithSpiderMonkey = "false"
+}
+
+# If spidermonkey was disabled but JS_ENGINE set to "spidermonkey", reset it 
to "quickjs"
+if ( ($WithSpiderMonkey -eq "false" ) -and ($JS_ENGINE -eq "spidermonkey" ) ) {
+   Write-Verbose "NOTICE: Spidermonkey was disabled, but 
JS_ENGINE=spidermonkey. Setting JS_ENGINE=quickjs"
+   $JS_ENGINE = "quickjs"
+}

Review Comment:
   Small nit / var names:
   
   While Powershell isn't case-sensitive for variable names, let's use the same 
spelling.
   
   ```suggestion
   if ( ($WithSpiderMonkey -eq "false" ) -and ($JSEngine -eq "spidermonkey" ) ) 
{
      Write-Verbose "NOTICE: Spidermonkey was disabled, but 
JSEngine=spidermonkey. Setting JSEngine=quickjs"
      $JSEngine = "quickjs"
   }
   ```
   



##########
src/chttpd/src/chttpd_node.erl:
##########
@@ -51,6 +51,17 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, 
_Node, <<"_versions">>]}
     UcaVer = couch_ejson_compare:get_uca_version(),
     ColVer = couch_ejson_compare:get_collator_version(),
     Hashes = crypto:supports(hashs),
+    EngineName = couch_server:get_js_engine(),
+    JsEngine =
+        case EngineName of
+            <<"spidermonkey">> ->
+                #{
+                    name => EngineName,
+                    version => couch_server:get_spidermonkey_version()
+                };
+            _Other ->
+                #{name => EngineName}

Review Comment:
   very low priority:
   
   Could we get a version number dynamically from somewhere?



##########
configure:
##########
@@ -75,6 +77,8 @@ Options:
   --rebar=PATH                use rebar by specified path (version >=2.6.0 && 
<3.0 required)
   --rebar3=PATH               use rebar3 by specified path
   --erlfmt=PATH               use erlfmt by specified path
+  --js-engine=ENGINE          default js engine: spidermonkey or quickjs

Review Comment:
   Small nit:
   
   ```suggestion
     --js-engine=ENGINE          use js engine: spidermonkey or quickjs 
(defaults to spidermonkey)
   ```
   



##########
src/docs/src/config/quickjs.rst:
##########
@@ -0,0 +1,122 @@
+.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
+.. use this file except in compliance with the License. You may obtain a copy 
of
+.. the License at
+..
+..   http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing, software
+.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+.. License for the specific language governing permissions and limitations 
under
+.. the License.
+
+.. default-domain:: config
+.. highlight:: ini
+
+=======
+QuickJS
+=======
+
+Configure QuickJS Javascript Engine.
+
+QuickJS is an new Javascript Engine installed alongside the default
+Spidermonkey engine. It's disabled by default, but may be enabled via
+configuration settings.
+
+The configuration toggle to enable and disable QuickJS by default is in
+:ref:`couchdb <config/couchdb>` ``js_engine`` section.
+
+To help evaluate design doc compatibility, without the penalty of resetting all
+the views on a cluster, there is a :ref:`scanner <config/scanner>` plugin,
+which will traverse databases and design docs, compile and then execute some of
+the view functions using both engines and report incompatibilities.
+
+.. _config/quickjs:
+
+.. versionadded:: 3.4
+
+QuickJS Options
+===============
+
+.. config:section:: quickjs :: QuickJS Engine Configuration
+
+    .. config:option:: memory_limit_bytes
+
+        Set QuickJS memory limit in bytes. The default is ``undefined`` and the
+        built-in C default of 64MB is used. ::
+
+            [quickjs]
+            memory_limit_bytes = 67108864
+
+.. config:section:: couch_quickjs_scanner_plugin :: QuickJS Scanner Plugin 
Settings
+
+Enable QuickJS Scanner plugin in :ref:`couch_scanner_plugins
+<config/scanner>` ``couch_scanner_plugins`` section.
+
+    .. config:option:: max_ddocs
+
+        Limit the number of design docs processed per database. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_ddocs = 100
+
+    .. config:option:: max_shards
+
+        Limit the number of shards processed per database. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_shards = 4
+
+    .. config:option:: max_docs
+
+        Limit the number of documents processed per database. These are the max
+        number of documents sent to the design doc functions. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_docs = 1000
+
+    .. config:option:: max_step
+
+        Limit the maximum step size when processing docs. Given that total
+        number of documents in a shard as N, if the max_docs is M, then the
+        step S = N / M. Then only every S documents will be sampled and
+        processed. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_step = 1000
+
+    .. config:option:: max_batch_items
+
+        Maximum document batch size to gather before feeding them through each
+        design doc on both QuickJS and Spidermonkey engines and compare the
+        results. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_batch_items = 100
+
+    .. config:option:: max_batch_size
+
+        Maximum memory usager for a document batch size. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_batch_size = 16777216
+
+    .. config:option:: after
+
+        A common :ref:`scanner <config/scanner>` setting to
+        configure when to execute the plugin after it's enabled. By default
+        it's ``restart``, so the plugin would start running after a node
+        restart::
+
+            [couch_quickjs_scanner_plugin]
+            after = restart
+
+    .. config:option:: repeat
+
+        A common :ref:`scanner <config/scanner>` setting to
+        configure when to execute the plugin after it's enabled. By default
+        it's ``restart``, so the plugin would start running after a node
+        restart::
+
+            [couch_quickjs_scanner_plugin]
+            repeat = restart

Review Comment:
   Same description for both config options?



##########
src/docs/src/config/quickjs.rst:
##########
@@ -0,0 +1,122 @@
+.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
+.. use this file except in compliance with the License. You may obtain a copy 
of
+.. the License at
+..
+..   http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing, software
+.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+.. License for the specific language governing permissions and limitations 
under
+.. the License.
+
+.. default-domain:: config
+.. highlight:: ini
+
+=======
+QuickJS
+=======
+
+Configure QuickJS Javascript Engine.
+
+QuickJS is an new Javascript Engine installed alongside the default
+Spidermonkey engine. It's disabled by default, but may be enabled via
+configuration settings.
+
+The configuration toggle to enable and disable QuickJS by default is in
+:ref:`couchdb <config/couchdb>` ``js_engine`` section.
+
+To help evaluate design doc compatibility, without the penalty of resetting all
+the views on a cluster, there is a :ref:`scanner <config/scanner>` plugin,
+which will traverse databases and design docs, compile and then execute some of
+the view functions using both engines and report incompatibilities.
+
+.. _config/quickjs:
+
+.. versionadded:: 3.4
+
+QuickJS Options
+===============
+
+.. config:section:: quickjs :: QuickJS Engine Configuration
+
+    .. config:option:: memory_limit_bytes
+
+        Set QuickJS memory limit in bytes. The default is ``undefined`` and the
+        built-in C default of 64MB is used. ::
+
+            [quickjs]
+            memory_limit_bytes = 67108864
+
+.. config:section:: couch_quickjs_scanner_plugin :: QuickJS Scanner Plugin 
Settings
+
+Enable QuickJS Scanner plugin in :ref:`couch_scanner_plugins
+<config/scanner>` ``couch_scanner_plugins`` section.
+
+    .. config:option:: max_ddocs
+
+        Limit the number of design docs processed per database. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_ddocs = 100
+
+    .. config:option:: max_shards
+
+        Limit the number of shards processed per database. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_shards = 4
+
+    .. config:option:: max_docs
+
+        Limit the number of documents processed per database. These are the max
+        number of documents sent to the design doc functions. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_docs = 1000
+
+    .. config:option:: max_step
+
+        Limit the maximum step size when processing docs. Given that total
+        number of documents in a shard as N, if the max_docs is M, then the
+        step S = N / M. Then only every S documents will be sampled and
+        processed. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_step = 1000
+
+    .. config:option:: max_batch_items
+
+        Maximum document batch size to gather before feeding them through each
+        design doc on both QuickJS and Spidermonkey engines and compare the
+        results. ::
+
+            [couch_quickjs_scanner_plugin]
+            max_batch_items = 100
+
+    .. config:option:: max_batch_size
+
+        Maximum memory usager for a document batch size. ::

Review Comment:
   
   ?
   ```suggestion
           Maximum memory usage for a document batch size. ::
   ```
   



##########
src/couch_quickjs/test/couch_quickjs_tests.erl:
##########
@@ -0,0 +1,71 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_quickjs_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+
+setup() ->
+    Ctx = test_util:start_couch(),
+    Ctx.
+
+teardown(Ctx) ->
+    config:delete("quickjs", "memory_limit_bytes", _Persist = false),
+    test_util:stop_couch(Ctx).
+
+quickjs_test_() ->
+    {
+        foreach,
+        fun setup/0,
+        fun teardown/1,
+        case os:type() of
+            {win32, _} ->
+                [];

Review Comment:
   Since compiling for Windows is working now, should we run the tests there 
too?



##########
src/docs/src/config/quickjs.rst:
##########
@@ -0,0 +1,122 @@
+.. Licensed under the Apache License, Version 2.0 (the "License"); you may not
+.. use this file except in compliance with the License. You may obtain a copy 
of
+.. the License at
+..
+..   http://www.apache.org/licenses/LICENSE-2.0
+..
+.. Unless required by applicable law or agreed to in writing, software
+.. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+.. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+.. License for the specific language governing permissions and limitations 
under
+.. the License.
+
+.. default-domain:: config
+.. highlight:: ini
+
+=======
+QuickJS
+=======
+
+Configure QuickJS Javascript Engine.
+
+QuickJS is an new Javascript Engine installed alongside the default

Review Comment:
   ```suggestion
   QuickJS is a new Javascript Engine installed alongside the default
   ```
   



##########
src/docs/src/config/couchdb.rst:
##########
@@ -247,3 +247,13 @@ Base CouchDB Options
 
             [couchdb]
             write_xxhash_checksums = false
+
+    .. config:option:: js_engine :: Set default Javascript Engine.
+
+        .. versionchanged:: 3.4
+
+        Select the default Javascript engine. Available options are
+        ``spidermonkey`` and ``quickjs``. The defaults is ``spidermonkey``::

Review Comment:
   ```suggestion
           ``spidermonkey`` and ``quickjs``. The default setting is 
``spidermonkey``::
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to