Page 3 of 4

Re: [NEW] Servoy Tutorials

PostPosted: Thu Nov 28, 2013 10:22 am
by pbakker
Hi Gary,

The numbers on initial load are not the whole picture: The first two variations with both only keep a list of PK's in memory (for most of the records in case you have many), so if you start using the FS to retrieve actual records, there will be the overhead of getting the record details from the database, while in the DataSet variant all data is already in memory. So in a real caching scenario, I expect the DataSet variant to outperform FoundSets even more than just the initial load difference.

Note that off course a DataSet is disconnected from the database, so any changes you (or another client) make are not reflected in the DataSet. You could resolve this by using the onDataBroadcast event to listen for changes in the underlying tables and update the DataSet accordingly. If done right, you can keep the cached DataSet also in memory between multiple calculation runs, so you need to get the DataSet only once per client session.

Another upside of the DataSet approach is that you can flatten your datastructure for easy processing (and again reducing back and forth's to the database to retrieve related records) and get only those columns that you actually need.

Something else I forgot to mention: your memoization approach: you store the cache against "this". But "this" for regular methods (so non-constructor functions called with the "new" keyword) points to the object they belong to. So in case of form or scope method, "this" points to the scope in which the method is declared. There is no problem dynamically adding a cache property to such a scope, but if you would have 2 memoization function in one scope, their caches would collide.

As for the example code I gave: if I copy and paste my example into a Script Editor in Servoy it works fine: no parse exceptions, no warnings and proper code completion. Which version of Servoy are you using?

The reason you cannot get it to output the name of the person is probably because you store it as this.first and you try to output this.firstName

As for not seeing the prototype in David's approach: he uses Object.create, which creates a new object with the object passed into the create function as first parameter as prototype. However, when created this way, the prototype property is not exposed (don't ask me why, it just how JavaScript is designed). You can get the prototype through Object.getPrototypeOf(yourObject). So Davids approach achieves the goal, but at the cost of having to type the object using JSDoc.

Paul

Re: [NEW] Servoy Tutorials

PostPosted: Thu Nov 28, 2013 3:29 pm
by GaryDotzlaw
Hi Harjo,

Actually, the test results are after repeatedly running the procedures, since that better emulated the problem I was trying to solve in Optimizing Code Performance. The estimating engine in this case, was using the same foundsets over and over again.

If I do a restart between each test, I see numbers like this:
  • 29666ms - loaded in chunks
  • 7082ms - pre-load all before the loop
  • 118ms - use a dataset
If I repeatedly run the procedures, in any order, without restart, I see numbers like this:
  • 23914ms - loaded in chunks
  • 238ms - pre-load all before the loop
  • 118ms - use a dataset
So, to your point, pre-load seems to benefit more from the Servoy cache.

In my case, pre-loading the foundset before the loop, and avoiding foundset.getSize() in the for clause (cache the record count into a var and use that instead), significantly contributed to improving the estimating engine performance from 8.7secs to under 1sec in stress testing. It was a simple change to how I wrote the for loop with foundsets, and that was the entire point I was trying to communicate in the article; I did not have to do a massive code rewrite.

Re: [NEW] Servoy Tutorials

PostPosted: Thu Nov 28, 2013 4:01 pm
by GaryDotzlaw
Paul,

  • Thanks for the further explanation on the dataset approach. I will keep this in mind for the future. In my original case, I did not want to rewrite a lot of code, so improving performance was easily achieved by simply writing a more efficient for loop using the foundset approach. No other code changes were needed in the methods, since they were designed originally to work with foundset records.
  • I agree, function memoization is for a single cache in the function, although you can store as much as you want in that single cache. I will update the article so that no one tries more than one cache in a function that end up colliding.
  • Thank you for catching my typo in the prototype methods. Your example is working now (final code below). Parse error is gone now as well (Servoy 7.3.0 build 2018).
  • Thank you for the explanation on why David's example worked, despite not being able to see the prototype. I thought he was doing magic(another programming technique).

Code: Select all
/**
* @constructor
* @extends {personProto}
*/
function Person(first, last, title) {
   this.first = first;
   this.last = last;
   this.title = title;
}

function personProto() {
     function privateMember(){}

   this.fullName = function(){
      return this.first + " " + this.last;
   };
   this.fullNameTitle = function(){
      return this.fullName() + ", " + this.title;
   };

   /**
   * @protected
   */
   this.protectedMember = function(){
      return "You cannot see me!";
   };
}
var initPerson = (function(){
   Person.prototype = new personProto();
   Person.prototype.constructor = Person;
}())

// and then later to use
var x = new Person('SomeOther','Buddy','JavaScript Servoy Blogger');
application.output(x.fullName()) //CodeCompleting for .name() and no builder markers
// outputs SomeOther Buddy

Thanks again for the feedback.

Re: [ANN] 2 NEW Servoy Tutorials

PostPosted: Fri Nov 29, 2013 5:30 am
by GaryDotzlaw
I have added two more tutorials to my site. I modified the list at the start of this thread; refer to it for the complete library.

The two new tutorials are:


I hope you enjoy them!

Re: [NEW] Servoy Tutorials

PostPosted: Fri Nov 29, 2013 4:19 pm
by david
Nice prototype inheritance and object based inheritance comparison: http://uxebu.com/blog/2011/02/23/object ... ascript-5/

[ANN] New Servoy Tutorial

PostPosted: Sun Dec 01, 2013 8:48 pm
by GaryDotzlaw
I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The a new tutorial is:


I hope you enjoy it!

Re: [ANN] Another Servoy Tutorial

PostPosted: Tue Dec 03, 2013 8:47 pm
by GaryDotzlaw
I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The a new tutorial is:


I hope you enjoy it!

Re: [ANN] Another Servoy Tutorial

PostPosted: Wed Dec 04, 2013 12:22 pm
by juan.cristobo
GaryDotzlaw wrote:I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The a new tutorial is:


I hope you enjoy it!


Thanks Gary, this tutorial is awesome!!

Re: [NEW] Servoy Tutorials

PostPosted: Wed Dec 04, 2013 12:58 pm
by grahamg
Thanks again Gary - don't you ever sleep!

I use Arrays quite a bit - but beginning to realise how much more they can do. Really useful insights.

Cheers

Re: [ANN] New Servoy Tutorial

PostPosted: Thu Dec 05, 2013 2:02 am
by GaryDotzlaw
Thanks guys.
I'll sleep when I'm dead. - Bon Jovi

I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The new tutorial is:

I hope you enjoy it!

Re: [ANN] NEW Servoy Tutorial - Automated Testing

PostPosted: Mon Dec 09, 2013 3:44 pm
by GaryDotzlaw
I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The new tutorial is:


I hope you enjoy it!

Re: [ANN] New Servoy Tutorial- Using GitFlow and SourceTree

PostPosted: Wed Dec 11, 2013 12:48 am
by GaryDotzlaw
I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The new tutorial is:


I hope you enjoy it!

Re: [ANN] New Servoy Tutorial - Encapsulation

PostPosted: Fri Dec 13, 2013 6:09 am
by GaryDotzlaw
I have added a new tutorial to my site. I modified the list at the start of this thread; refer to it for the complete library.

The new tutorial is:


There is a second part coming, that demonstrates how to put the lessons learned in this tutorial to good use.

I hope you enjoy this tutorial!

Re: [ANN] New Servoy Tutorial - Event Driven Architecture

PostPosted: Mon Dec 16, 2013 5:59 pm
by GaryDotzlaw
Sorry, I forgot to post an announcement here for a new tutorial I released on the weekend. If you like the tutorials, then please consider subscribing at my site, so you are notified when new ones are posted; I might miss posting here.

I modified the list at the start of this thread; refer to it for the complete library.

The new tutorial is:


I hope you enjoy this tutorial!

Re: [ANN] New Servoy Tutorials

PostPosted: Fri Dec 27, 2013 6:24 pm
by GaryDotzlaw
I released two additional tutorials a while ago, so just updating this thread.

The new tutorials are:


If you like the tutorials, then please consider subscribing at my site, so you are notified when new ones are posted.