Consideration about Marshaller class..

Nov 14, 2011 at 9:27 AM

Hi to all,

I wanted to share with you a little consideration about Marshaller class.

First of all lets say i've always used jint 0.8.9 in my application, and i found it great :)

Now, after a lot of tests and some editing i decided to update jint to version 0.9.2

The new version suits perfectly with my application and it works very good, there's only one thing that doesn't convince me..
Jint 0.9.2 inizialization is much slower than 0.8.9..

In my application, time is very important, and a minimal slowdown could result in a complaint :P

I've taken some data to explain what i mean.
Times below refer to the initialization of a JintEngine (just the "new" instruction), values are approximated:

first time inizialization
----
0.8.9 = 40365 micros 
0.9.2 = 84775 micros 

further inizializations
----
0.8.9 = 323 micros
0.9.2 = 2019 micros

We are talking about microseconds.. so it's not a big deal, but for my needs can be a problem, not so much the first time inizialization but the further ones.

I did some tests and i found the possible solution in Marshaller class.

I made it static (following CachedTypeResolver class as example) and i obtained these results:

inizializations after the first
---
0.8.9 = 323 micros
0.9.2 = 292 micros

My problems seem solved, but i wanted to hear your opinion about this change.

Can be proper to make Marshaller object static?
Why is not already?

Thank you in advance for any replies (and of course for your work).

Nov 14, 2011 at 11:16 AM

Each Marshaller instance is bound to the global js object, and using them to marshal primitives and assing correct prototypes

Nov 14, 2011 at 12:49 PM

Hi Cin, thanks for replying.

What i wanted to know is if it can be correct to have a static Marshaller object, instead of one instance for each js object.

I saw it has a dictionary<type, nativeConstructor> that on each instance of jint contains always the same values..

Instanziating it only one, on first inizialization, let me save a lot of time in case i create lots of jintengine consecutively.

Nov 14, 2011 at 1:05 PM

These dictionaries are not the same, every CRL type is mapped to the js function (see NativeConstructor class) which have it's own 'prototype' property, if you made a static Marshaller this will lead to sharing it between JintEngine instances and any changes you made to it in one engine will be reflected in others.

Nov 16, 2011 at 3:24 PM

Hi Cin,

I solved my slowdown problem using only one jintEngine instead of having an instance created each time, i just added a method to clear its globalscope to avoid a little problem.

I'll do my tests, but it seems to work, thanks for your help.

Nov 16, 2011 at 9:05 PM

Hi,

Glad to see that you solved your problem.

Please note that you can run your scripts in closures

(function(){

// you script here

})();

And this will protect your global object from modifications in most cases, from adding new properties, for example, but if you are modifing standart properties, you'll need a more complex solution.