I have a list of DyamicVariables that I would like to set at the same time.
If there were two in the list the code would look like so.
state: state during: aBlock
DynamicVar1 use: (DynamicVar newValueFor: state) during: [ DynamicVar2 use: (DynamicVar newValueFor: state) during: aBlock ]
Now if there were any number of this things in an OrderedCollection how would I efficiently or otherwise evaluate this code nested n times deep.
thanks in advance
Keith
Now if there were any number of this things in an OrderedCollection how would I efficiently or otherwise evaluate this code nested n times deep.
The easiest would be if you let a specific dynamic variable return an object (e.g. an ordered-collection or a dictionary), that knows all your objects.
There is also the package DynamicBindings, that provides a whole framework for doing things like this.
Lukas
Lukas Renggli wrote:
Now if there were any number of this things in an OrderedCollection how would I efficiently or otherwise evaluate this code nested n times deep.
The easiest would be if you let a specific dynamic variable return an object (e.g. an ordered-collection or a dictionary), that knows all your objects.
There is also the package DynamicBindings, that provides a whole framework for doing things like this.
Lukas
Hi Lukas,
Overnight I came to the same conclusion, that what I was trying was too complex for a simple problem.
I am trying to support a number of orthogonal requirements on WASession without subclassing, but it doesnt have a properties dictionary where I can stuff things. I need slots for more than one db session, and an announcements announcer amongst other things.
Thanks for the suggestion, I could have just one other DynamicVariable working in tandem with WACurrentSession and that could hold the other values.
How performant are these DynamicVariable lookups?
many thanks
Keith
How performant are these DynamicVariable lookups?
They are quite performant, if your stack has a reasonable size and you are calling the lookup a reasonable number of times. There is a primitive in the VM that answers the next context possible handler.
I remember a project where dynamic variables were used to translate every individual string displayed on the page. The rendering was not measurably slower than in the untranslated case.
If you need raw speed, it might be smart to add an additional variable to Process which provides you with O(1) performance. However since this is much trickier to port, we don't use it in Seaside.
I am co-author of an not yet published paper that compares the two approaches in the discussion. The observed numbers for 10^6 queries are the following:
Stack depth Dynamic Variables Process Variable 0 7455 ms 258 ms 100 7967 ms 258 ms 1000 17883 ms 255 ms
Cheers, Lukas
squeak-dev@lists.squeakfoundation.org