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
This commit is contained in:
commit
83e24bab6d
@ -257,7 +257,7 @@ class Table
|
|||||||
*/
|
*/
|
||||||
private function renderColumnSeparator()
|
private function renderColumnSeparator()
|
||||||
{
|
{
|
||||||
$this->output->write(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
|
return sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,12 +274,12 @@ class Table
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->renderColumnSeparator();
|
$rowContent = $this->renderColumnSeparator();
|
||||||
foreach ($this->getRowColumns($row) as $column) {
|
foreach ($this->getRowColumns($row) as $column) {
|
||||||
$this->renderCell($row, $column, $cellFormat);
|
$rowContent .= $this->renderCell($row, $column, $cellFormat);
|
||||||
$this->renderColumnSeparator();
|
$rowContent .= $this->renderColumnSeparator();
|
||||||
}
|
}
|
||||||
$this->output->writeln('');
|
$this->output->writeln($rowContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -306,12 +306,13 @@ class Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($cell instanceof TableSeparator) {
|
if ($cell instanceof TableSeparator) {
|
||||||
$this->output->write(sprintf($this->style->getBorderFormat(), str_repeat($this->style->getHorizontalBorderChar(), $width)));
|
return sprintf($this->style->getBorderFormat(), str_repeat($this->style->getHorizontalBorderChar(), $width));
|
||||||
} else {
|
}
|
||||||
|
|
||||||
$width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
|
$width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
|
||||||
$content = sprintf($this->style->getCellRowContentFormat(), $cell);
|
$content = sprintf($this->style->getCellRowContentFormat(), $cell);
|
||||||
$this->output->write(sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType())));
|
|
||||||
}
|
return sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user