Open enricogior opened 7 years ago
updateViewInQueue(view) calls processNextBatch()
processNextBatch() calls tryCode(view.sourceDB, mapFun, [doc])
tryCode(db, fun, args) calls fun.apply(null, args) where fun
maps to mapFun that in our case is mapFun = evalFunction(view.mapFun.toString(), emit);
evalFunction
maps to evalFunctionInVm
The sandbox (aka VM) is created for every item in the result list and that causes a significant performance issue.
Note that this bug started life as thaliproject/jxcore#82, which itself started life from thaliproject/leveldown-mobile#4 (where there is sample code that repro's this issue).
So it seems like the core of our problem is that vm.runInNewContext runs 90x too slow on JXcore versus anywhere else. So we want to get rid of it.
I sent mail to Nolan looking at three options:
I talked with Nolan and there are a couple of options for us here. Using the list above:
I modified our test app to add pouchdb-find tests: TestViewsMobile
The results of query/find execution are as follow for 6000 documents: WebView with view: 20s WebView with index (find): 20s Jxcore with view: 300s Jxcore with index (find): 20s
As you can see the for WebView there is no difference - building the index for the first usage is similar like building the view. However, for jxcore we are getting significant improvement - we are getting the same result as in WebView.
Quick update: Using pouchdb-find instead of views works for us so we are fine at this moment.
The map reduce code invokes evalFunctionInVm even for non user defined functions.
https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-mapreduce/src/index.js#L477
https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-mapreduce/src/evalFunctionInVm.js
Test results using https://github.com/czyzm/TestViewsJx with JXcore and V8: