nickva commented on issue #3517:
URL: https://github.com/apache/couchdb/issues/3517#issuecomment-891897388


   Discussing this on couchdb-dev channel, CouchDB with JS runtimes later than 
mozjs 60 need to re-write their design doc functions [1]. Also, unlike pure map 
views, where the JS runtime gets to process (learn) the function first, then 
only handle the keys and values [2], custom reduce functions have the function 
body sent with each query server command. Therefore, any overhead in that JS 
code re-writing is amplified for the custom reducers.
   
   Looking back at the reduce function, I wonder if it would be possible to 
rewrite it using two _sum[3] and _stats[4] built-in reducers, which should not 
suffer from the same rewriting overhead.
   
   For example, the _sum reducer can be applied to objects, such as:
   
   ```
   "views":{"v1":{ "map": "function(doc){ emit(null, {x:doc.x, y:doc.y}) };", 
"reduce":"_sum"}}
   ...
   {"x": 1, "y": 3}
   {"x": 2, "y": 4}
   ```
   And would emit:
   ```
   {"key":null,"value":{"x":3,"y":7}}
   ```
   
   That could be used for "unsuccessful" results. For the "successful" case, 
execution stats could be accumulated using _stats [3]
   
   
   [1] 
https://github.com/apache/couchdb/blob/0059b8f90e58e10b199a4b768a06a762d12a30d3/share/server/60/rewrite_fun.js#L29-L38
   [2] 
https://docs.couchdb.org/en/stable/query-server/protocol.html?highlight=add_fun#add-fun
   [3] https://docs.couchdb.org/en/stable/ddocs/ddocs.html#_sum
   [4] https://docs.couchdb.org/en/stable/ddocs/ddocs.html#_stats


-- 
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