MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: *slowing down* a Mathematica process (Dynamic/Refresh question)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101182] Re: [mg101100] *slowing down* a Mathematica process (Dynamic/Refresh question)
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Fri, 26 Jun 2009 06:49:31 -0400 (EDT)
  • Reply-to: jfultz at wolfram.com

I said this in my earlier post, but perhaps obliquely.

The inner call prevents updates which are caused by changes to x.  I.e., every 
time x changes, the Dynamic is immediately invalidated and posted for 
revalidation (meaning re-evaluation) as soon as the FE needs to draw it again.  
If it's on-screen, that means right away.  Since every attempt to display the 
Dynamic changes x (because of the increment operator), this is going to cycle 
very quickly.

I think this is much like what's happening in your code.  Without having seen 
it, I can't be for sure, but I suspect that every time you poll, you're changing 
the value of some variable.  That variable then invalidates the Dynamic and
forces you into a loop that executes much faster than you want.  You have to
prevent that dependency from re-triggering the Dynamic, and that's what 
Refresh[_, None] does.

But, having killed the trigger, you need to add a new one.  This one will force 
things to update every second, even though no other trigger has occurred.  
That's what the outer call to Refresh does.  I didn't have to do that part with 
Refresh.  I could have also done it with Clock.  E.g.,

x = 0; Dynamic[Clock[{0, 1, 1}]; Refresh[x++, None]]

I see another poster suggested using TrackedSymbols->{}.  That's yet another
legitimate method (in combination with Refresh or Clock) of accomplishing the 
same thing.

Sincerely,
 
John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Wed, 24 Jun 2009 21:16:39 -0400, Michael Stern wrote:
> John, that's great. One question -- why the nested calls to Refresh[]?
>
> Michael
>
>
> John Fultz wrote:
>
>> To restate your problem in a way which can be observed without your
>> code,
>>
>> I think you're looking for this...
>>
>> x = 0; Dynamic[Refresh[x++, UpdateInterval -> 1]]
>>
>> to update at 1 second intervals rather than the minimum of 1 second and
>> the amount of time it takes to change x (which, in this case, is far
>> less than 1 second).  To do this, you should do something like...
>>
>> x = 0; Dynamic[Refresh[Refresh[x++, None], UpdateInterval -> 1]]
>>
>> I.e., you're removing entirely the trigger of the changing value of x
>> that causes the Dynamic to update, then adding a new trigger which
>> causes an update every second.
>>
>> Sincerely,
>>
>> John Fultz
>> jfultz at wolfram.com
>> User Interface Group
>> Wolfram Research, Inc.




  • Prev by Date: Re: TeX output via TeXForm: variable name translation
  • Next by Date: Re: Non-converging integral with linear transformation?!
  • Previous by thread: Re: *slowing down* a Mathematica process (Dynamic/Refresh question)
  • Next by thread: Possible bug in Mathematica 7 using ColorFunction