3

I have 8 variables to be manipulated, and it costs a lot of CPU power to have this dynamic environment standby all the time, being refreshed when it's not needed.

It's not that the evaluation is slow, it's the Manipulate working hard at "idling" so that my entire computer is slow to respond to any action.

Even though in my Manipulate environment, I have set all the variables to discrete step of 1 (with each having range of about 100), the load is still too heavy.

I remember seeing in the documentation long ago an option for Dynamic[ something ] with a coder specified rate of update (esp. useful in 3-dim graphics), but I cannot locate where it is now.

How do I set Manipulate refresh time to e.g. once per second? (note that this is not about the rate of animation)

I feel like this should be just a basic command. Any pointer would be appreciated. Thanks for your time.

Below is a reduced version of my actual code. It appears not as minimal as one would like, but I guess the point is to include all the possible problematic parts.

bigN = 160;  ImgSz = 400;
Manipulate[
 data = {   { {x111, x112}, {x121, x122}
    }, {{x211, x212}, {x221, x222}  }   };
 s = 1/2; 
 sT = -5/3 s; sP = 6/5 sT; 
  Graphics3D[{  
   { Red, Opacity[0.2], Polygon[{
      {sP, -s, -s}, {sP, -s, 1 + s}, {sP, 1 + s, 1 + s}, {sP, 
       1 + s, -s}
      }]}
   , myStyle = Style[#, Background -> White, FontSize -> 28] &;
   Table[ Text[ data[[1 + i, 1 + j, 1 + k]] // myStyle, {i, j, k} ]
    , {i, 0, 1}, {j, 0, 1}, {k, 0, 1} ] 
   }, ImageSize -> ImgSz, 
  BoxRatios -> {4, 3, 2}
  , Axes -> True , AxesLabel -> {"X", "Y", "Z"}] 
 , Grid[{   
   {Control[{
      {x112, bigN/8, "Up11"},  bigN/16, (3 bigN)/16, 1
      }], Spacer[20]
    , Control[{
      {x122, bigN/8, "Up12"}, bigN/16, (3 bigN)/16, 1
      }]   }, {Control[{
      {x212, bigN/8, "Up21"},   bigN/16, (3 bigN)/16, 1
      }], Spacer[20]
    , Control[{
      {x222, bigN/8, "Up22"},   bigN/16, (3 bigN)/16, 1
      }]   
    } }  ], Grid[{  (* lower layer *)
   {Control[{
      {x111, bigN/8, "Low11"},  bigN/32, bigN/4, 1
      }], Spacer[20]
    , Control[{
      {x121, bigN/8, "Low12"},  bigN/32, bigN/4, 1
      }]   }, {Control[{
      {x211, bigN/8, "Low21"},  bigN/32, bigN/4, 1
      }], Spacer[20]
    , Control[{
      {x221, bigN/8, "Low22"},  bigN/32, bigN/4, 1
      }]   
    } }  ], ControlPlacement -> {Top, Bottom}]

1 Answers1

3

You can make your demo run somewhat more snappy by moving as much computation as possible outside the refresh loop. It also good to minimize the number of dynamic variables being tracked.

Here is some work along that line that I did.

With[{
  bigN = 160, imgSz = 400, s = 1/2,
  myStyle = (Style[#, Background -> White, FontSize -> 28] &)},
  With[{sT = -5/3 s, sP = 6/5 sT},
    Manipulate[
      data = {{{x111, x112}, {x121, x122}}, {{x211, x212}, {x221, x222}}};
      Graphics3D[
        {{Red, Opacity[0.2], 
          Polygon[
            {{sP, -s, -s}, {sP, -s, 1 + s}, {sP, 1 + s, 1 + s}, {sP, 1 + s, -s}}]},
         Table[
           Text[data[[1 + i, 1 + j, 1 + k]] // myStyle, 
           {i, j, k}], {i, 0, 1}, {j, 0, 1}, {k, 0, 1}]},
         ImageSize -> imgSz,
         BoxRatios -> {4, 3, 2},
         Axes -> True, 
         AxesLabel -> {"X", "Y", "Z"}], 
      Grid[
        {{Control[{{x112, bigN/8, "Up11"}, bigN/16, (3 bigN)/16, 1}], 
          Spacer[20], 
          Control[{{x122, bigN/8, "Up12"}, bigN/16, (3 bigN)/16, 1}]}, 
         {Control[{{x212, bigN/8, "Up21"}, bigN/16, (3 bigN)/16, 1}], 
          Spacer[20], 
          Control[{{x222, bigN/8, "Up22"}, bigN/16, (3 bigN)/16, 1}]}}], 
      Grid[
        {{Control[{{x111, bigN/8, "Low11"}, bigN/32, bigN/4, 1}], 
          Spacer[20], 
          Control[{{x121, bigN/8, "Low12"}, bigN/32, bigN/4, 1}]}, 
         {Control[{{x211, bigN/8, "Low21"}, bigN/32, bigN/4, 1}],
          Spacer[20], 
          Control[{{x221, bigN/8, "Low22"}, bigN/32, bigN/4, 1}]}}], 
      TrackedSymbols :> {x111, x112, x121, x122, x211, x212, x221, x222},
      ControlPlacement -> {Top, Bottom}]]]

I admit I didn't see a lot improvement in responsiveness, but then the original code didn't respond slowly on my system.

Edit

When I put this demo on Autorun with bigN = 320, set the speed so fast that the screen refresh couldn't keep up, it put a 10.4% load on my CPU. That's not going to cause any system slowdown.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • I've never used With in a dynamic before, and TrackedSymbols is new to me. I'll look into those. Thank you. In my actual program, there's already improvement with the TrackedSymbols line. – Lee David Chung Lin Dec 10 '16 at 03:39
  • Also see (http://mathematica.stackexchange.com/questions/37805). After trying for real the necessarily nested With layers outside of DynamicModule[ Manipulate[ . ] ] along with TrackedSymbols, my program improved substantially even as it gets bigger. The With in really crucial. Thanks. – Lee David Chung Lin Dec 14 '16 at 09:13