From: Timothy J. H. <tim...@ma...> - 2004-07-16 03:08:45
|
On Jul 9, 2004, at 2:55 PM, Ken Anderson wrote: > Tim, > Let me know what you think of this proposal. > > Currently a DynamicVariable has 3 fields > Symbol name > DynamicEnvironment dynamicenv - used to look up value in hash table. > Object storedDynamicValue - only used during serialization. > > A DynamicEnvironment, DE, maps symbols to values. > So every time we evaluate a DV, we do a hash lookup. > > I'd like to propose we > 1. put the DV's value in the storedDynamicValue field > 2. remove the dynamicenv field. > 3. Change DE to map from Symbol -> DV. I agree. I'd thought about this optimization before and it makes great sense. > This means the DE will intern the DV for a symbol, but it can use its > current hashtable to do that. getBindings and importBindings would > have to clone all the DV's (or could they be shared?). I think they could be shared. Modules are assumed to be locked (i.e. you can't change the bindings of toplevel symbols) and so there would be no need to clone. > > The advantage is we'd get rid of a runtime hash lookup for every > global value. Yes. I tried to see whether this would make a dramatic difference by comparing two expressions which differ only in their use of globally defined symbols: > (define fib (lambda (n) (if (< n 3) 1 (+ 1 (fib (- n 1)) (fib (- n 2)))))) > (define fib2 (let ((+ +) (- -) (< <)) (lambda(n) (if (< n 3) 1 (+ 1 (fib (- n 1)) (fib (- n 2))))))) > (time (fib 25) 1) (150049 (986 msec) (20776 bytes)) > (time (fib2 25) 1) (150049 (916 msec) (3288 bytes)) Here the code in the closure of fib2 uses only local variables and hence should be doing four fewer hash table lookups for each procedure call, but I don't see much in the way of time differences.... I really expected a bigger time difference. The regular approach gets 152K procedure calls per second (on a Powerbook G4 with jdk1.4) and the fancier approach gets 163K pc/sec which is about a 7% improvement. ---Tim--- |