You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "nickva (via GitHub)" <gi...@apache.org> on 2023/05/25 00:00:32 UTC

[GitHub] [couchdb] nickva opened a new pull request, #4622: Add QuickJS as a Javascript engine option

nickva opened a new pull request, #4622:
URL: https://github.com/apache/couchdb/pull/4622

   https://bellard.org/quickjs
   https://fuchsia.googlesource.com/third_party/quickjs/
   
   Some benefits over SM:
   
    * Small. We're using 6 or so C files vs 700+ SM91 C++ files.
   
    * Built with Apache CouchDB as opposed having to maintain a separate SM package, like for RHEL9, for instance, where they dropped support for SM already. (see https://github.com/apache/couchdb/issues/4154).
   
    * Embedding friendly. Designed from ground-up for embedding. SM has been updating the C++ API such that we have to keep copy-pasting new versions of our C++ code every year or so. (see https://github.com/apache/couchdb/pull/4305).
   
    * Easy to modify to accept Spidermonkey 1.8.5 top level functions for map/reduce code so we don't have have to parse the JS, AST trasform it, and then re-compile it.
   
    * Configurable runtime feature set - can disable workers, promises and other API and features which may not work well in a backend JS environment. Some users may want more, some may want to disable even Date(time) features to hedge again Spectre-style attacks (spectreattack.com).
   
    * Allows granular time (reduction) trackign if we wanted to provide a runtime allowance for each function.
   
    * Better sandboxing. Creating a whole JSRuntime takes only 300 microseconds, so we can afford to do that on reset. JSRuntimes cannot share JS data or object between them.
   
    * Seems to be faster in preliminary benchmarking with small concurrent VDU and view builds: https://gist.github.com/nickva/ed239651114794ebb138b1f16c5f6758 Results seem promising: - 4x faster than SM 1.8.5 - 5x faster than SM 91 - 6x reduced memory usage per couchjs process (5MB vs 30MB)
   
    * Allows compiling JS bytecode ahead of time a C array of bytes.
   
   QuickJS can be built alongside spidermonkey and toggled on/off at runtime:
   
   ```
   ./configure --dev --js-engine=quickjs
   ```
   
   This makes it the default engine. But spidermonkey can still be set in the config option.
   
   ```
   [couchdb]
   js_engine = spidermonkey | quickjs
   ```
   
   Only tested on MacOS and Linux. All `make check` tests pass there.
   
   Issue: https://github.com/apache/couchdb/issues/4448
   


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [couchdb] nickva closed pull request #4622: Add QuickJS as a Javascript engine option

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva closed pull request #4622: Add QuickJS as a Javascript engine option
URL: https://github.com/apache/couchdb/pull/4622


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [couchdb] rnewson commented on pull request #4622: Add QuickJS as a Javascript engine option

Posted by "rnewson (via GitHub)" <gi...@apache.org>.
rnewson commented on PR #4622:
URL: https://github.com/apache/couchdb/pull/4622#issuecomment-1562488098

   This looks to be a great improvement on several fronts. I think we should go all in on this. maybe optional for a release or two and then fully switch? once we can assume an embedded JS engine we can boost a number of areas (like VDU's).


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [couchdb] nickva commented on pull request #4622: Add QuickJS as a Javascript engine option

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on PR #4622:
URL: https://github.com/apache/couchdb/pull/4622#issuecomment-1562079877

   **QuickJS**
   
   ```
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.10s user 0.22s system 7% cpu 18.754 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.05s user 0.21s system 6% cpu 18.438 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.06s user 0.21s system 6% cpu 18.591 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.06s user 0.20s system 6% cpu 18.279 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.09s user 0.22s system 6% cpu 18.822 total
   ```
   
   Memory usage 5MB-7MB RSS per couchjs process (based on btop output)
   
   **Spidermonkey 1.8.5**
   
   ```
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.33s user 0.25s system 2% cpu 1:06.80 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.31s user 0.24s system 2% cpu 1:05.80 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.32s user 0.24s system 2% cpu 1:04.34 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.31s user 0.23s system 2% cpu 1:03.00 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.34s user 0.25s system 2% cpu 1:13.93 total
   ```
   
   **Spidermonkey 91**
   
   ```
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.11s user 0.21s system 1% cpu 1:31.13 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.09s user 0.20s system 1% cpu 1:24.22 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.10s user 0.21s system 1% cpu 1:35.53 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.06s user 0.20s system 1% cpu 1:20.57 total
   ./stampede_dbs_ddocs_vdus.py -x 10 -n 100 -w 20 -t 3  1.07s user 0.20s system 1% cpu 1:22.06 total
   ```
   
   Memory usage 30-32MB RSS per couchjs process (based on btop output)
   
   
   Runtime metrics capture (also quick and dirty courtesy of btop):
   
   <img width="1052" alt="file1" src="https://github.com/apache/couchdb/assets/211822/aad22ad0-3e96-4aa8-a840-aa8e44288a16">
   <img width="1059" alt="file2" src="https://github.com/apache/couchdb/assets/211822/e9736666-5fee-4ade-b8bb-e8c1f22969b5">
   
   The CPU usage graph is quite telling I think.


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [couchdb] nickva commented on pull request #4622: Add QuickJS as a Javascript engine option

Posted by "nickva (via GitHub)" <gi...@apache.org>.
nickva commented on PR #4622:
URL: https://github.com/apache/couchdb/pull/4622#issuecomment-1569253706

   Switching pull request to use the branch off the Apache CouchDB main since otherwise Jenkinsfile updates don't have an effect. Closing in favor of https://github.com/apache/couchdb/pull/4627


-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org