Search

User: Developer

Prerequisites

- not applicable

Introduction

Explanation of how to handle with xml operations to improve performance of a Futurama application

 

Description

Applications that are built in Futurama frequently deal with several XML operations. For example the processing of an XML-file with users data. The way that this data is treated within Futurama can have a huge impact on the performance. At this page a couple of examples are given of situations where XML-operations are used. For each of these examples is shown how to improve the performace by chosing another way to model this process within the Futurama document.

Situation 1

The first situation is a simple application that gets numbers from a large xml file and makes calculations with those numbers. The xml file is a 100-by-120 matrix with numbers, with ages from 0 to 120 over the columns and years from 2012 to 2112 over the rows. In the Futurama document a calculation is made where a series of numbers are taken as XmlFields with a complex XPath query from the matrix. This happens for a particular age, age+1 and year and are taken diagonal from the matrix. Now there are two series of numbers, a serie starting with age and year and a serie starting with age+1 and year. Then from these two series are taken 4 numbers, so that the numbers can be interpolated to one number for a particular age. This calculation is repeated for a specified range of ages.

Problem

The problem in situation 1 is that retrieving two XmlFields with diagonal series of numbers from the matrix costs much time. This is because the XPath query depends on variable values that change at each calculation. And because of this the XmlFields are evaluated again at each calculation. The structure of the calculation is the next: an XmlBuilder that loops over a specified range of ages, the age is used in a formula that converts the age into a birthdate. This birthdate is used in a complex XPath query that goes through the matrix in a diagonal. This XPath query retrieves an array of 121 elements from the matrix, this happens twice. After this, 4 elements from the arrays are used to calculate an interpolated number for the specified age. All these action are repeated for each calculation, because the age changes.

Solution

The solution to increase the speed of situation 1 is not to retrieve the XmlFields with the arrays every time the application makes a calculation. To save time the application has to read the whole matrix once and to retrieve the 4 numbers without xpath queries, but with an index function. The trick is to find a formula that does the same as the complex XPath query.

Download files

There is an example Futurama application that contains the calculation and solution described above. When you open the file “xmlperformance.xml” in Futurama (5.2+) you can see the difference in performance of the two calculations. When you click on the xmlbuilder “calculation 1”, you can see in the result box, under the node that the calculation takes about 9 seconds. This is the calculation with the complex XPath queries. Now reset the document (right click document|reset) and click on “calculation 2”. You see the same result but in less time. Now it only takes 0.3 seconds, because this calculation uses an index function instead of XPath queries.

Situation 2

Second situation is another application with an example where data from users files is read to make calculations with it. In this simple example only the birthdates from the users files is used to calculate the age of the users.

Problem

The problem in the second situation is that the reading of user data from an xml file costs much time. All the user data is stored in one single file. The structure of the application is: an XmlBuilder with a loop calculates the ages for all the users and writes them to an xml file. Per user an XmlNode with XmlFields is read from the input xml with an index of the user-ID. This way the XmlNodes with XmlFields are evaluated for each user again. These xml operations cost much time.

Solution

The solution is to avoid xml operations as much as possible. In this situation xml operations are avoided by reading the whole xml file with all the user data once and put it in matrices per element of the user data. Now the application loops over the matrices with the users-ID.

Download files

There is an example Futurama application that contains the calculation and solution described above. When you open the file “xmlperformance2.xml” in Futurama (5.2+) you can see the difference in performance of the two calculations. When you click on the XmlBuilder “calculation 1”, you can see in the result box, under the node that the calculation takes about 3 seconds. This is the calculation where the xml is evaluated each time. Now reset the document (right click document|reset) and click on “calculation 2”. You see the same result but in less time. Now it only takes 0.3 seconds, because this calculation uses of matrices.

Feedback

If you have any questions about this subject or if you want to provide us feedback please send us an e-mail.

Updated: 2016-07-29