Re: [v8-users] BSON to v8::Object performance issue

2017-11-17 Thread Jean-Marc Le Roux
Thank you! Great help here. Amazing folks! On Nov 17, 2017 6:21 PM, "J Decker" wrote: > > > On Fri, Nov 17, 2017 at 7:25 AM, Jean-Marc Le Roux < > jeanmarc.ler...@aerys.in> wrote: > >> My assumption is that my test app terminates before the GC has a chance >> to run. >> To

Re: [v8-users] BSON to v8::Object performance issue

2017-11-17 Thread J Decker
On Fri, Nov 17, 2017 at 7:25 AM, Jean-Marc Le Roux wrote: > My assumption is that my test app terminates before the GC has a chance to > run. > To test this: > >- I run node with the --expose-gc option >- I call global.gc() at the end of my test app > > In this

Re: [v8-users] BSON to v8::Object performance issue

2017-11-17 Thread Jean-Marc Le Roux
My assumption is that my test app terminates before the GC has a chance to run. To test this: - I run node with the --expose-gc option - I call global.gc() at the end of my test app In this case, the destructor of my ObjectWrap is indeed called. *So it seams the GC doesn't simply

Re: [v8-users] BSON to v8::Object performance issue

2017-11-17 Thread Jean-Marc Le Roux
Thanks for the great help! I think it makes a lot of sense now. So I've extended ObjectWrap like so: class BSONObject : public node::ObjectWrap > { > private: > bson_t* _bson; > public: > BSONObject(bson_t* bson, Local tpl) : > _bson(bson) > { > Local obj =

Re: [v8-users] BSON to v8::Object performance issue

2017-11-16 Thread J Decker
You don't manage the instance, the v8 engine does. When it's no longer referenced in the engine, it's garbage collected which triggers the callback set when the perisstent object is made weak. You don't need to keep it anywhere, the object returned into the engine has Internal Fields (

Re: [v8-users] BSON to v8::Object performance issue

2017-11-16 Thread Jean-Marc Le Roux
> > Node offers a C++ Clss extention ObjectWrap Thanks ! It is related to node. Yet I'm not sure how I'm supposed to use ObjectWrap. I understand I have to create my own class that extends ObjectWrap and implement a proper destructor. Then I'll instanciate that class to wrap my Local. But how

Re: [v8-users] BSON to v8::Object performance issue

2017-11-16 Thread J Decker
On Thu, Nov 16, 2017 at 1:24 AM, Jean-Marc Le Roux wrote: > I assume you're storing references to the objects as Persistent? > > > Nope. You've got the whole code up there. > So if I understand correctly: > >- the objects I need to keep track of the lifecycle

Re: [v8-users] BSON to v8::Object performance issue

2017-11-16 Thread Jean-Marc Le Roux
> > I assume you're storing references to the objects as Persistent? Nope. You've got the whole code up there. So if I understand correctly: - the objects I need to keep track of the lifecycle should be made Persistent ; - all the other values can be set as Local ; - I should set

Re: [v8-users] BSON to v8::Object performance issue

2017-11-15 Thread J Decker
I assume you're storing references to the objects as Persistent? All you need to do then is call SetWeak() https://v8docs.nodesource.com/node-0.10/d2/d78/classv8_1_1_persistent.html void MakeWeak (void *parameters, WeakReferenceCallback callback) the callback is called when the object is GC'd.

Re: [v8-users] BSON to v8::Object performance issue

2017-11-15 Thread Jean-Marc Le Roux
So I've found a solution to make things lazy: I set an accessor instead of decoding/setting the actual value. void getter(Local property, const PropertyCallbackInfo& info) { Isolate* isolate = info.GetIsolate(); const bson_t* document = reinterpret_cast( info.This()

Re: [v8-users] BSON to v8::Object performance issue

2017-11-15 Thread Jean-Marc Le Roux
> > Now it takes *30ms. That's still 5x faster* than the native code. 300ms. (not 30) On Wed, Nov 15, 2017 at 10:27 AM, Jean-Marc Le Roux < jeanmarc.ler...@aerys.in> wrote: > Thanks for the quick feedback! > > I rewrote the JS version to be closer to the native one: > > var array = []; > var

Re: [v8-users] BSON to v8::Object performance issue

2017-11-15 Thread Jean-Marc Le Roux
Thanks for the quick feedback! I rewrote the JS version to be closer to the native one: var array = []; var input = { "_id": { "$oid": "5a00bad8f759511811e030ba" }, "attributes": [ { "key": "smartshape.scene.node.path|default", "value": "/scene/Lot444.scene",

Re: [v8-users] BSON to v8::Object performance issue

2017-11-14 Thread Jakob Kummerow
There are a bunch of optimizations going into object literal handling, so the two versions are not at all equivalent: the JS version is expected to be much faster. To make them more comparable, you could model the same control flow in JS, roughly: var input = { "_id": { "$oid":

[v8-users] BSON to v8::Object performance issue

2017-11-14 Thread Jean-Marc Le Roux
Hello, I'm trying to create NodeJS bindings for libbson. One of the things I need is to be able to transform a bson_t document into a v8::Object. Loading, iterating on bson_t documents and matching them with MongoDB-style queries it very fast: 50ms to load from my HDD, iterate and filter 26000