zsh-workers
 help / color / mirror / code / Atom feed
* Option reorganisation, Part IV.
@ 1996-12-27 23:02 Zoltan Hidvegi
  1996-12-30 10:33 ` Zefram
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-12-27 23:02 UTC (permalink / raw)
  To: Zsh hacking and development

Here is the next step in using hashtable for options.  This depends on
Zefram's previous rewite in article 2612.

After this patch the optns array is no longer used.  Loops over this array
are replaced with scanhashtable and scanmatchtable calls.

After this patch it'll be quite easy to add new options dynamically.
This patch also decreases the memory used by zsh a little bit.

Only init.c, main.c and options.c needs to be recompiled for this patch, so
you can continue using your old modules.

Zoltan


begin 644 opt4.patch.gz
M'XL(`*11Q#(``^T\:W?:2+*?F5_1]NZ,P8$$\"N)D^S!6+%98_`%G'&<9#(R
M"*,Q2%Q))'$2[V^_5?V0^B5,)C.S>^Y9[ZQCJ:NJN^M=I98V-S=)/QH^"N>)
M'P;QPV&A]N3)[J-:_5%]E]1VG^[4GE;W"EL/:_"_^@^52B4/>H_4ZT^WJT]W
M=G_85'_PFFP]+N]L$WI)2)Q$BV%"@$K@SCSR!6[AS[$;3SKAR".!]RG9+Q0>
M;=*_B!^0"0R1X<2%/S<?<7"XC,@F4`!0A*4P(S=Q$62-@O@!FR7D(&S=)%C,
MKKR(4;K;AU\_L,D'[M74XT")>\5'`&\P\<C0#<+`'[K3E`JN/:$HE!+,^;>1
M-_8#CW3/!N^;_>-"H5@CSYX1Y_2\W1@X>*ND09V84"<FE`EDPER:0)<(1?<@
M`S;:;0#D2_S*%_&53?.54RII.`?=\U['85@9=(DJ!(KV,8&_*G^U:,=3]SK>
MYS<6`0KE"UP5&'J23N5.?3<F"9UPS'G0:O09L8*L)#8=8>3OR&+_3U<725%L
M>B)IB$5!,M6P:8:D$W^N2MBL?V>W7-O;$N8O4^ET.S(A6`CYB?PKHZ_/"O"X
M'1U8:+JZ<;[G0O73=E42K1^3R)MZ'UP0?!(2;[:8NG2`"EMAZYG3;#7:0."Q
M3"">A(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@JIQOJN\P8FT$&Y`*D?A-C5V&&SPS6BM^T[[(`U+G
M.=,?QH_E"J+H1Z8>R_FWR;^K]SF>/)PHW]1[\G1G^^GV8_Y-O9WTFWI6R*VG
MVW7[$0Y(0&JU]$S`#]D!!\P\F\>-7I^L_^WOOVP62\^_?KE[\^[79R_^\:_]
MG]X&;Q/R]NW;C;?KZ\Q<Z`-XD;YA.W/0/2G3[U%5299U]9TSIR>>JG><G]LM
M<?R"+X0KR?<NA)T$^'W+L?'IR?9V^<G.CL0GH'06QK&/FDH-.\9(J;Q3+/,%
M-5EJXY01OPG+],#G<T67/LM&AT_"*+!#(`!"'(2@*IX=!LI("O-KX.*I_8VT
M_;0F/_<0]1F&>T^TSU`>;,-;DCQ6W;"0F[1;0O#]YUK)V+0.>R)@ZR4;!W1P
MA*;@6R4[.W2$2T%_NV3ES5*VV.UG=Z=<J^[5TD-0BP#F9%%44F(65?'U;5JA
M7;R3WW"G!1A[MSL=K>2\^LU"[476)6*?:I1>`M<^U2C>W!")@/1J1DE>Q&_A
MU166R`*.'W0OE;AY[F[!/G?Y!QJ%6YJY?B!_O7,'O_59!;^T8WSK4P?=0\=4
MVWI:W<N)<N7=NIQ@CT<T*KS'YYZTOG$Z[T\;%_OJ,(R(!Z0R0DG.G:5#&:DW
M%VV1K!5;*^VS`.6+1X.@"+,PUGK-^$.%EKU,@35WD=:Y'S`!VZALI--02,[9
M=RR=HW/,("^_XHJ`01#G?.^'['L"-(92=DBIT!_&#NNYD_]\IOP?WB[WEG%6
"``"=
`
end


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Option reorganisation, Part IV.
  1996-12-27 23:02 Option reorganisation, Part IV Zoltan Hidvegi
@ 1996-12-30 10:33 ` Zefram
  1996-12-30 15:53   ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Zefram @ 1996-12-30 10:33 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zsh-workers

Zoltan Hidvegi wrote:
>After this patch the optns array is no longer used.  Loops over this array
>are replaced with scanhashtable and scanmatchtable calls.

But it *is* used.  It has to be used to insert the initial options into
the hashtable.  Any use of it after that we get for free, so there's no
reason not to look up the flags and so on there.  And walking through
the table is faster than scanhashtable(), for those functions that need
to look at all the options.

>After this patch it'll be quite easy to add new options dynamically.

But do we *want* to?  I don't like the idea of options that can't be
set until the appropriate module has been loaded.  And autoloaded
options would be silly, and would cause unnecessary module loading.  I
think options should really affect only the core functionality.
Anything else can use command line switches or parameters.

You store aliases in a manner that requires a second name lookup, but
it's easier and more efficient to store the actual option number.  (And
the way you handle the structures with the union is not strictly
conforming, and quite likely to break on 64-bit machines using the LP64
model.)  I don't see the point in doing this.

You also changed the {z,k}shletters arrays to be of the enum type,
rather than short.  This is a bad idea.  On 32-bit machines the enum is
most likely larger -- if we really want the extra speed in table
lookups we should be more sure of it by using int.  More importantly,
the enum could be unsigned, but the table contains negative values.
And there are probably some compilers that would warn about the use of
a value that is not one of the enumeration constants.  (For these
reasons, I *never* use an enum as a type.)

-zefram


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Option reorganisation, Part IV.
  1996-12-30 10:33 ` Zefram
@ 1996-12-30 15:53   ` Zoltan Hidvegi
  1996-12-31 12:27     ` Zefram
  0 siblings, 1 reply; 5+ messages in thread
From: Zoltan Hidvegi @ 1996-12-30 15:53 UTC (permalink / raw)
  To: Zefram; +Cc: zsh-workers

Zefram wrote:
> Zoltan Hidvegi wrote:
> >After this patch the optns array is no longer used.  Loops over this array
> >are replaced with scanhashtable and scanmatchtable calls.
> 
> But it *is* used.  It has to be used to insert the initial options into
> the hashtable.  Any use of it after that we get for free, so there's no
> reason not to look up the flags and so on there.  And walking through
> the table is faster than scanhashtable(), for those functions that need
> to look at all the options.

Yes it is faster but not much faster and it is quite rarely needed.  I do
not see why should we use hashtables if we do not use scanhashtable.  If
you want to use the array you might as well stay with the old system adding
binary search to optlookup to make it faster.

Hashtable functions has the advantage that the order of the options does
not matter.  If we add all new options to the end of the enum list we do
not have to recompile everything and we can keep optns list alpabetically
ordered.

> >After this patch it'll be quite easy to add new options dynamically.
> 
> But do we *want* to?  I don't like the idea of options that can't be
> set until the appropriate module has been loaded.  And autoloaded
> options would be silly, and would cause unnecessary module loading.  I
> think options should really affect only the core functionality.
> Anything else can use command line switches or parameters.

I did not want to move zle options to the zle module.  But one might
implement a new module which requires some new options.

I did not think about autoloaded options but even if an option is
autoloaded it can be set without the module where it is used.

> You store aliases in a manner that requires a second name lookup, but
> it's easier and more efficient to store the actual option number.  (And

Yes but againg you do not win much here.  I could store numbers for aliases
but that without optno -> name reverse lookup I'll not be able to print
these aliases.

One more argument: builtins has been stored in a static array before
modules appeared and noone wanted to use array functions on them.  But I
know it is a bad example.

> the way you handle the structures with the union is not strictly
> conforming, and quite likely to break on 64-bit machines using the LP64
> model.)  I don't see the point in doing this.

The struct iparam in hashtable.h is even worse.  And this can be made
safer:

    for (on = optns; on->nam; on++)
        optiontab->addnode(optiontab, on->nam, (Optname) on);

where on is of the same as optns, and similarily for optals.  That would
only assume that the union is alligned the same was as int and char *.

In hashtable.h the code assumes that sizeof(long) == sizeof(void *).
That can be fixed by duplicating the table but that would just waste memory
for nothing (at least noone complained so far).

> You also changed the {z,k}shletters arrays to be of the enum type,
> rather than short.  This is a bad idea.  On 32-bit machines the enum is
> most likely larger -- if we really want the extra speed in table
> lookups we should be more sure of it by using int.  More importantly,
> the enum could be unsigned, but the table contains negative values.
> And there are probably some compilers that would warn about the use of
> a value that is not one of the enumeration constants.  (For these
> reasons, I *never* use an enum as a type.)

I agree here, I'll change that.

Zoltan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Option reorganisation, Part IV.
  1996-12-30 15:53   ` Zoltan Hidvegi
@ 1996-12-31 12:27     ` Zefram
  1997-01-01 17:57       ` Zoltan Hidvegi
  0 siblings, 1 reply; 5+ messages in thread
From: Zefram @ 1996-12-31 12:27 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zefram, zsh-workers

Zoltan Hidvegi wrote:
>Yes it is faster but not much faster and it is quite rarely needed.  I do
>not see why should we use hashtables if we do not use scanhashtable.  If
>you want to use the array you might as well stay with the old system adding
>binary search to optlookup to make it faster.

The point of a hashtable is to make name lookups very quick.
scanhashtable() is used when it is necessary to look at all elements in
a hash table; in this case it is not necessary, as there is another,
easier, way to look at all the options.  And, of course, going through
the hash table elements means that alias entries will also be
encountered, and must be ignored, whereas going through the option
table avoids this.

>Hashtable functions has the advantage that the order of the options does
>not matter.  If we add all new options to the end of the enum list we do
>not have to recompile everything and we can keep optns list alpabetically
>ordered.

That already applies.  The reason we have to recompile is that we keep
the enum in alphabetical order too.  Anyway, we don't add options very
often.

>I did not want to move zle options to the zle module.  But one might
>implement a new module which requires some new options.

There are other mechanisms than these options.

>I did not think about autoloaded options but even if an option is
>autoloaded it can be set without the module where it is used.

Then autoloading an option is equivalen to letting the user create new
options on the fly.  I really don't think we want to do that.

>Yes but againg you do not win much here.  I could store numbers for aliases
>but that without optno -> name reverse lookup I'll not be able to print
>these aliases.

I don't see what you mean here.  The option aliases should never be
output; they're just extra names that can be used when specifying
options.  All that is needed of an option alias is a mapping from name
to number, and putting the number directly in the hash table element
achieves this with the minimum of fuss.  There is simply no need to map
from alias name to canonical name.

>One more argument: builtins has been stored in a static array before
>modules appeared and noone wanted to use array functions on them.  But I
>know it is a bad example.

The difference here is that options *are* internally identified by
number, not name.  The system I produced had options operated on by
number internally, with simple table lookups to get the option flags
and canonical name, and used the hashtable only to map user-specified
names to numbers.  Your system uses names internally in some places,
and numbers in other places.

>> the way you handle the structures with the union is not strictly
>> conforming, and quite likely to break on 64-bit machines using the LP64
>> model.)  I don't see the point in doing this.
>
>The struct iparam in hashtable.h is even worse.

That's no excuse!  :-)

The code can be made more portable by having two structures, one being
the normal structure with the union, and the other the same but with
the union members the other way round.  It is possible to initialise
the first member of a union, so by using these two structures you get
the ability to initialise either member of the union.  An
implementation would have to be actively perverse for this to fail.

-zefram


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Option reorganisation, Part IV.
  1996-12-31 12:27     ` Zefram
@ 1997-01-01 17:57       ` Zoltan Hidvegi
  0 siblings, 0 replies; 5+ messages in thread
From: Zoltan Hidvegi @ 1997-01-01 17:57 UTC (permalink / raw)
  To: Zefram; +Cc: zefram, zsh-workers

Zefram wrote:
> The point of a hashtable is to make name lookups very quick.

All right.  Show me any scipt which runs measurably slower after my patch,
and I'll restore using the array.

> scanhashtable() is used when it is necessary to look at all elements in
> a hash table; in this case it is not necessary, as there is another,
> easier, way to look at all the options.  And, of course, going through

Yes, there is but theoretically it is cleaner to use hashtable functions
only.  And just to show how much more complicated the hash-scan code:

        for (i = 0; i < ht->hsize; i++)
            for (hn = ht->nodes[i]; hn; hn = hn->next)
                if (!(hn->flags & flags2))
                    scanfunc(hn, scanflags);

The if condition skipps four option aliases.  The overhead is this four
skipped options (from 108), and for each option one pointer dereference and
assignment, two conditional jump and a function call/return.  At worst this
means a few dozen machine cycles.

With setopt without arguments which prints all options, there is the
overhead to sort the options but that's again unnoticable in interactive
usage and setopt without arguments is used very rarely in scripts.

> >Yes but again you do not win much here.  I could store numbers for aliases
> >but that without optno -> name reverse lookup I'll not be able to print
> >these aliases.
> 
> I don't see what you mean here.  The option aliases should never be
> output; they're just extra names that can be used when specifying
> options.  All that is needed of an option alias is a mapping from name
> to number, and putting the number directly in the hash table element
> achieves this with the minimum of fuss.  There is simply no need to map
> from alias name to canonical name.

I just thought that a form of setopt to print option aliases would be
nice.  But I really do not think that necessary and I'll gladly remove
textual aliases together with this union hack.

Zoltan


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-01-01 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-27 23:02 Option reorganisation, Part IV Zoltan Hidvegi
1996-12-30 10:33 ` Zefram
1996-12-30 15:53   ` Zoltan Hidvegi
1996-12-31 12:27     ` Zefram
1997-01-01 17:57       ` Zoltan Hidvegi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).