|
When used properly (more below), CGIDEV2 variable substitution performance just isn't an issue.
When CGIDEV2 reads a template record, it stores it in a memory-resident stream and places its offset into a memory resident array of offsets.
If the record contains any substitution variables, it makes an entry for each into a set of memory resident arrays that contain the substitution variable's RRN, starting position in its record, the substitution string, the length of the substitution string, and the section name.
When a section is written, CGIDEV2 uses the HTML records' offsets to extract each HTML record from the memory resident stream and %lookup with the record's RRN (%lookup uses binary search, so it's fast) to ascertain whether it has any substitution variables. If so, the entries in the arrays are used to perform variable substitution. It was designed to be and is very efficient.
The part that involves a lot of work is processing the template into the stream and the arrays.
However, that processing does not have to be performed every time the CGI program runs because the 2nd and subsequent runs in the same activation group reuse the data previously stored in the stream and the arrays.
I always recommend that frequently used CGIDEV2 programs be created with named activation groups. In such programs, once template processing has been done, it is not done again until the list of template files changes or any of them is modified (date/timestamp changes). Usually, this is not during the activation group's lifetime.
If multiple programs use the same activation group, each of them should use the same list of template files to ensure that the templates are not processed again and again. Alternatively, each program could have its own activation group name.
The things that most slow down CGIDEV2 are not using named activation groups and leaving debugging on after it is no longer needed.
Mel Rothman CGIDEV2 Author Seth Newton wrote:
Brad,In a CGIDEV2 application, there is an HTML template that uses replacement variables where your dynamic content will go. At runtime, APIs are used to search/replace the replacement variables with their appropriate values. The difference in performance is quite noticeable, especially with a subfileapplication that loads many records.RPGsp’s compile process pre-determines which variables and expressions will be need to be output to the browser at compile-time. When the application runs, sections of HTML are output as needed, and the value of variables or expressions are also output directly, with no search/replace taking place. As an example, let's say this is our template: Item Number: <%ITEM%> <br> Item Description: <%DESC%> With CGIDEV2 and other similar tools, the logic flows like this: 1. Read Template. 2. Search my template for <%ITEM%> and replace it with RPG variable ITEM. 3. Search my template for <%DESC%> and replace it with RPG variable DESC. 4. Output template. Steps 2 and 3 are CPU-intensive. In a subfile application, these Search steps may be repeated thousands of times. RPGsp, on the other hand, reads the template at compile time, andrestructures it to execute like this.1. Output "Item Number:"2. Output the value of RPG variable ITEM 3. Output "<br> Item Description:"4. Output the value of RPG variable DESC Here, we have no CPU-intensive search/replace logic, which results in muchfaster code.Seth Newton snewton@xxxxxxxxxxxxxxxxx Profound Logic Software, Inc. Toll-Free: (877) 224-7768 x115 Fax: (603) 849-7757 RPGsp - iSeries Web Development has never been this easy! Watch video demos: http://www.profoundlogic.com/video_demos/ -----Original Message-----I am used to working with CGI from RPGsp (www.RPGsp.com), which allows you to embed RPG variables into HTML templates. However, the templates are not searched at runtime. The pages are compiled in a similar way JSP's are created, and that's why it's fast ... most likely faster than equivalent JSP's.Explain how this works. how can data from a DB be replaced anywhere exceptfor runtime.Any time you're building dynamic applications data HAS to be inserted/replaced/built at runtime. Brad
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.