[SERVER-2579] change v8 wrapper to be lazy Created: 17/Feb/11  Updated: 12/Jul/16  Resolved: 02/May/11

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 1.9.1

Type: Improvement Priority: Major - P3
Reporter: Eliot Horowitz (Inactive) Assignee: Antoine Girbal
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-2407 Switch to v8 Closed
Participants:

 Description   

we need to make the BSON to v8 conversion lazy rather than aggressive, at least optionally.
so in map/reduce for example, if you only access 2 ints, you don't convert a huge object



 Comments   
Comment by free [ 31/Aug/11 ]

Seems it won't depents on SERVER-2407 Switch to v8, u can remove this dependency

Comment by auto [ 13/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-2579: print warning if modifying r/o object
Branch: master
https://github.com/mongodb/mongo/commit/17e2688d76428cacad37f89252882bbf046f0bda

Comment by auto [ 10/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-2579: added readonly object for lazy v8 objects, which makes them much faster to access
SERVER-2976: further implementation of jsMode for M/R. Can be turned on using temp flag jsMode:true
Branch: master
https://github.com/mongodb/mongo/commit/13e71279c964fc3f84e682901f37152935557f70

Comment by auto [ 02/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-2579: optimize append() method to use same BSONObj builder throughout process
Branch: master
https://github.com/mongodb/mongo/commit/04d364a44d34b22c2c44df9240025bc01730ae1d

Comment by auto [ 02/May/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-2579: all v8 object creation is now lazy.
Correct allocation and freeing of underlying C++ object.
Correct ordering of object properties even when new ones are added within JS.
Supports deletion of properties with lazzy wrapper.

Also removed scope->setThis in favor of passing it in the invoke() command.
Branch: master
https://github.com/mongodb/mongo/commit/1725803c209ddf6ca52190447ddb1bdbc7371719

Comment by auto [ 25/Apr/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-2579: added framework for lazy v8
Branch: master
https://github.com/mongodb/mongo/commit/c75b2cbae1b0d6315324cd94a11d4ea460676047

Comment by auto [ 25/Apr/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-2579: added framework for lazy v8
Branch: master
https://github.com/mongodb/mongo/commit/c75b2cbae1b0d6315324cd94a11d4ea460676047

Comment by Antoine Girbal [ 19/Apr/11 ]

Been doing some testing with wrapper and the performance is quite slower (2x) when using lazily populated arrays vs creating whole array ahead.
Most likely it's due to the creation of array of keys when iterating, and the use of interceptors.
Assuming that once an array is requested in js, most likely most values will be accessed, so it would makes sense to create full array.
The lazy access would still remain for any object / subobject.
This would also makes things cleaner in code because v8 does not support array creation from a template, and I had to add some hacks to make an object behave like an array.

Comment by Antoine Girbal [ 06/Apr/11 ]

so when I started v8 seemed to be quite slow, about 10x for a simple group.
Did following so far:

  • implemented lazy access to fields
  • use global objectTemplate instead of creating 1 for each object
  • a few other optims
    This brought the group performance in line with spider monkey for small objects.

This get the following results for mr1.js
antoine@ag410:~/workspace/tengen/mongo$ grep timeMill newv8.log
"timeMillis" : 28,
"timeMillis" : 1,
"timeMillis" : 2,
"timeMillis" : 3,
"timeMillis" : 42,
"timeMillis" : 36,
"timeMillis" : 947,
"timeMillis" : 745,
antoine@ag410:~/workspace/tengen/mongo$ grep timeMill spider.log
"timeMillis" : 33,
"timeMillis" : 1,
"timeMillis" : 3,
"timeMillis" : 3,
"timeMillis" : 73,
"timeMillis" : 78,
"timeMillis" : 1358,
"timeMillis" : 923,

so far about 20-30% gain, potentially more as objects get much larger.
I have to look at each field translation details see if that can be improved.

Generated at Thu Feb 08 03:00:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.