New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid re-compiling filter view functions #4473
Conversation
d048ed4
to
7495a4e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a JS expert by any means, but this seems like a nice optimization, and I'm assuming there are many tests in CI that exercise this code already.
Filter view functions feature re-uses view map function for filtering _changes feeds. Instead of accumulating emitted KVs, it uses custom emit() function which just toggles a flag. However, in order to use this optimisation, the function is compiled first with the regular emit function, then the function source is queried with a non-portable toSource() method, and re-compiled again with a new sandbox where emit is overridden. Instead of reparsing and re-compiling it, pass the sandbox to the compile function and compile filter views with that correct sandbox to start with. Moreover, this helps remove another non-portable function call.
7495a4e
to
6090633
Compare
Good point @jaydoane. I knew about the new chttpd tests but I double-checked to verify we had a bunch more as well: couchdb/src/chttpd/test/eunit/chttpd_changes_test.erl Lines 485 to 493 in 1381631
couchdb/src/couch_replicator/test/eunit/couch_replicator_filtered_tests.erl Lines 119 to 139 in 1407a51
couchdb/test/elixir/test/changes_test.exs Lines 110 to 118 in adf1714
|
Filter view functions feature re-uses view map function for filtering _changes feeds. Instead of accumulating emitted KVs, it uses custom emit() function which just toggles a flag. However, in order to use this optimisation, the function is compiled first with the regular emit function, then the function source is queried with a non-portable toSource() method, and re-compiled again with a new sandbox where emit is overridden.
Instead of reparsing and re-compiling it, pass the sandbox to the compile function and compile filter views with that correct sandbox to start with. Moreover, this helps remove another non-portable function call.