On Mon, 22 Mar 2010, Maurilio Longo wrote:

Hi,

> > For tables which have very big number of fields the speed
> > improvement should be huge. Accessing fields by name is
> > relatively very slow operation and all RDD methods which
> > transfer records between workareas use such translation
> > table with indexes to eliminate it.
> Przemyslaw, sorry if my question is a dumb one, but could the HVM+RDDs use
> such translation table for the normal code?
> I have, I think we all have, plenty of code doing
> alias->name :=
> or
> var := alias->name
> in loops as well, so If this could be made faster at runtime, when the
> position of fields cannot change between every dbUseArea()/dbCloseArea() pair,
> this could be a speed boost which gives some noticeable result.
> Maybe this cannot be done, but maybe every alias->field could be compiled into
> a lookup table indexed expression and the lookup table be compiled by 
> dbUseArea().
> What do you think?

In code which uses field names explicitly by symbols, i.e.
   alias->name
then name is replaced by reference to global symbol table (PHB_DYNS)
and then address of PHB_DYNS is used to access the field. This eliminates
str[i]cmp() in code which scan fields in workarea for field index. Only
PHB_DYNS addresses are compared so it faster then using pure name to detect
field index.
The improvement you are asking for can be implemented but it needs deeper
modifications in compiler, HVM and RDD code. It will be necessary to
introduce to HVM for each alias used in the code arrays with field symbols
and their indexes. Such arrays have to be created at applications startup
code and then updated inside RDD open/close operation and also in some other
ones like HB_DBDETACH()/HB_DBREQUEST() or proposed by Mindaugas alias rename.
The field symbols in symbol table will have to be marked by Harbour compiler
in special way using HB_FS_*() flags so at application startup they can be
recognized by code which registers symbols in HVM. At the beginning they
should contain in 'value' union index to alias symbol and registration
code should check if such field name exists in table of field names bound
with given alias and if not then it should add it. Finally it should take
the index of the field in this table and store it in 'value' union inside
field symbol. Then at runtime HVM will use this index to retrieve field
index from array with field names bound with active workarea.
It should work with some cost of additional memory necessary to create
the tables with field names but only with code which explicitly uses field
names and aliases.
It's also possible to make some farther improvement for code using
   alias->name
by adding new PCODE which will replace two ones generated by current
compiler code. Now we have:
   HB_P_PUSHSYM, 0, 1,              /* ALIAS */
   HB_P_PUSHALIASEDFIELD, 2, 0,     /* NAME */
and then we will have:
   HB_P_PUSHALIASFIELD, 0, 1, 2, 0, /* ALIAS->NAME */
It will help to simplify a little bit code used for such dedicated PCODE.
Such improvement can be done even without introducing described above
tables with aliases. Anyhow number of PCODEs we can use is limited so
I do not know if such modification is important enough to add new PCODE.
For sure we can add it without any problems for -gc3 code because here
we are not limited by number of PCODEs.

best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to