@John Isael
This is a good level of response to this question to Dimuthu Dissanayake's question. We can overdo the detail for what sounds like a general introductory question. We can continue the discussion as Dimuthu requests more detail.
One additional note that obfuscates the performance aspect of your response is field-level caching that was introduced in UniVerse at 7.3.1 and in current versions of UniData. Field level cache stores field number and the offset of the last accessed field. This alters the performance profile of many workloads. Scanning fields sequentially (FOR NDX = 1 TO N; A = ARRAY<NDX>; NEXT NDX) becomes almost painless, and only about twice the time of using REMOVE in the same loop. While this suggests we should access fields in field number sequence to take advantage of field-level caching, I lean towards code clarity.
Decomposing each field into an array element wih MATREAD, the caching moves the tradeoff towards more field accesses in a record before needing the benefit of MATREAD. You seem to also lean in this direction. When curious, measure.
Further, note that caching, accessing sequential values in a field exhibits the same performance characteristics of accessing fields prior to the implementation of the cache. (FOR NDX = 1 TO N; A = ARRAY<X,NDX>; NEXT NDX) . In these cases, the RAISE() and LOWER() functions provide access to the values at the field level, and enable use of the caching mechanism.
------------------------------
Mark A Baldridge
Principal Consultant
Thought Mirror
Nacogdoches, Texas United States
------------------------------
Original Message:
Sent: 03-23-2023 08:38
From: John Isael
Subject: READ READV MATREAD
READ loads the entire record into a dynamic array.
READV loads a single field (which could be multi-valued) into a variable.
MATREAD loads an entire record into a dimensioned array.
READ is the most commonly used but can have minimal (very minimal) performance issues it there are a lot of fields. If you want to access field 100, the U2 program must parse through the prior 99 fields to get to it.
READV is best used if you know you only want to read 1 value from a record. If you want more than one, use a READ.
MATREAD takes the most coding, but is that fastest if you are going to be dealing with multiple fields in the same record. Unlike a READ, it you want to access field 100, the U2 program does NOT need to parse through the prior 99 fields.
Note that the parsing is transparent to the user - it is built into the U2 programming language. The bigger a record is and the more fields you wish to access, the slower the program will run due to the parsing. The more data it has to parse through to get the desired field, the slower it is. Again, this parsing tends to be fast. I rarely use MATREADs unless I know I am dealing with large records. That being said, if you have a program that is running slowly and deals with a lot of data, replacing the READs with MATREADs can have staggering performance improvements. It really comes down to: you need to know your data to make the best decision.
------------------------------
John Isael
Rocket Forum Shared Account
Original Message:
Sent: 03-22-2023 01:39
From: Dimuthu Dissanayake
Subject: READ READV MATREAD
what is the different between these commands READ READV and MATREAD and how the memory allocation and performance work in these commands.
------------------------------
Dimuthu Dissanayake
Software Engineer
Rocket Forum Shared Account
------------------------------