@@ -50,10 +50,10 @@ you can also set the current progress by calling the
50
50
51
51
If your platform doesn't support ANSI codes, updates to the progress
52
52
bar are added as new lines. To prevent the output from being flooded,
53
- adjust the
54
- :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::setRedrawFrequency `
55
- accordingly. By default, when using a `` max ``, the redraw frequency
56
- is set to * 10% * of your ``max ``.
53
+ adjust the update interval when this happens via these methods
54
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::preventRedrawFasterThan ` - write after each x second
55
+ :method: ` Symfony \\ Component \\ Console \\ Helper \\ ProgressBar::setRedrawFrequency ` - write each x iteration
56
+ By default, redraw frequency is ** 100ms ** or each ** 10% * * of your ``max ``.
57
57
58
58
If you don't know the exact number of steps in advance, set it to a reasonable
59
59
value and then call the ``setMaxSteps() `` method to update it as needed::
@@ -289,17 +289,23 @@ to display it can be customized::
289
289
290
290
.. caution ::
291
291
292
- For performance reasons, be careful if you set the total number of steps
293
- to a high number. For example, if you're iterating over a large number of
294
- items, consider setting the redraw frequency to a higher value by calling
295
- :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::setRedrawFrequency `,
292
+ By default, for performance reasons Symfony redraws screen every 100ms.
293
+ In special cases, this can be too often and might hurt performance.
294
+ In other cases, this can be opposite and it hurts UX.
295
+ In either of these cases, consider tweaking redraw frequency by either of these methods:
296
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::preventRedrawFasterThan `
297
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::setRedrawFrequency `
298
+ :method: `Symfony\\ Component\\ Console\\ Helper\\ ProgressBar::forceRedrawSlowerThan `
296
299
so it updates on only some iterations::
297
300
298
301
$progressBar = new ProgressBar($output, 50000);
299
302
$progressBar->start();
300
303
301
- // update every 100 iterations
302
- $progressBar->setRedrawFrequency(100);
304
+ // redraw every 100 iterations or every 200ms (in case iterations go too slow)
305
+ $progressBar->setRedrawFrequency(200);
306
+ $progressBar->forceRedrawSlowerThan(0.2);
307
+ // but don't redraw sooner than every 100ms (in case iterations go too fast)
308
+ $progressBar->preventRedrawFasterThan(0.1);
303
309
304
310
$i = 0;
305
311
while ($i++ < 50000) {
0 commit comments