Skip to content

Commit 83e24ba

Browse files
committed
minor #18966 [console] Improve table rendering performance (aik099)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #18966). Discussion ---------- [console] Improve table rendering performance | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #18957 | License | MIT | Doc PR | - With these improvements on my application, that is rendering table with 128 rows and 5 columns I've cut off total application runtime from **0.39s** to **0.26s**. Commits ------- 73b812e Make one call to "OutputInterface::write" method per table row
2 parents 2e93849 + 73b812e commit 83e24ba

File tree

1 file changed

+11
-10
lines changed
  • src/Symfony/Component/Console/Helper

1 file changed

+11
-10
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private function renderRowSeparator()
257257
*/
258258
private function renderColumnSeparator()
259259
{
260-
$this->output->write(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
260+
return sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar());
261261
}
262262

263263
/**
@@ -274,12 +274,12 @@ private function renderRow(array $row, $cellFormat)
274274
return;
275275
}
276276

277-
$this->renderColumnSeparator();
277+
$rowContent = $this->renderColumnSeparator();
278278
foreach ($this->getRowColumns($row) as $column) {
279-
$this->renderCell($row, $column, $cellFormat);
280-
$this->renderColumnSeparator();
279+
$rowContent .= $this->renderCell($row, $column, $cellFormat);
280+
$rowContent .= $this->renderColumnSeparator();
281281
}
282-
$this->output->writeln('');
282+
$this->output->writeln($rowContent);
283283
}
284284

285285
/**
@@ -306,12 +306,13 @@ private function renderCell(array $row, $column, $cellFormat)
306306
}
307307

308308
if ($cell instanceof TableSeparator) {
309-
$this->output->write(sprintf($this->style->getBorderFormat(), str_repeat($this->style->getHorizontalBorderChar(), $width)));
310-
} else {
311-
$width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
312-
$content = sprintf($this->style->getCellRowContentFormat(), $cell);
313-
$this->output->write(sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType())));
309+
return sprintf($this->style->getBorderFormat(), str_repeat($this->style->getHorizontalBorderChar(), $width));
314310
}
311+
312+
$width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
313+
$content = sprintf($this->style->getCellRowContentFormat(), $cell);
314+
315+
return sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType()));
315316
}
316317

317318
/**

0 commit comments

Comments
 (0)