janl opened a new pull request #3728:
URL: https://github.com/apache/couchdb/pull/3728
Since supporting SpiderMonkey versions > 1.8.5 we compile design
doc functions of the form `function(args) { /* impl */ }` into a
form that is recognise by newer JS engines.
For reduce views, this means a transpilation happens on each
reduce call over the couchjs protocol, which is once for every
level in the b+tree plus one final rereduce across all shards.
down reduce view indexing/querying.
This patch adds caching to the compilation function. This is
implemented by way of producing a SHA-256 hash of all incoming
JS functions and caching them in a global object in the memory
of a `couchjs` process.
The cache is cleared when a `add_fun` message is received, which
happens before new map functions from a new ddoc are loaded into
`couchjs`. This ensures that only functions from a single view &
security context are ever loaded into the cache.
SHA-256 was chosen because it is producing collisions that are
also valid JS functions is unlikley.
This specific SHA-256 implementation was chosen because:
- it is favourably licensed (MIT)
- taken from the Deno (https://deno.land) project, (h/t Martin
Sonnenholzer for the tip)so we can be reasonably assured this
has been tested thoroughly.
--
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]